Skip to content

Commit

Permalink
lint: fix TestForbiddenImports
Browse files Browse the repository at this point in the history
We need to set `Dir` in the `packages.Load()` call or else the whole
thing doesn't work. It would be really nice if it threw an error instead
of simply doing nothing, but it is what it is. To guard against this in
the future I added an error if the list is empty.

Fix the test then all existing violations, except for `raftlogger` which
will need some extra TLC by the owning team (see cockroachdb#132262)

Closes cockroachdb#132258

Epic: none
Release note: None
  • Loading branch information
rickystewart committed Oct 10, 2024
1 parent 258ea1c commit 63a0968
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1629,12 +1629,19 @@ func TestLint(t *testing.T) {
pkgs, err := packages.Load(
&packages.Config{
Mode: packages.NeedImports | packages.NeedName,
Dir: crdbDir,
},
pkgPath,
)
if err != nil {
return errors.Wrapf(err, "error loading package %s", pkgPath)
}
// NB: if no packages were found, this API confusingly
// returns no error, so we need to explicitly check that
// something was returned.
if len(pkgs) == 0 {
return errors.Newf("could not list packages under %s", pkgPath)
}
for _, pkg := range pkgs {
for _, s := range pkg.Imports {
arg.Out <- pkg.PkgPath + ": " + s.PkgPath
Expand Down Expand Up @@ -1666,6 +1673,7 @@ func TestLint(t *testing.T) {
stream.GrepNot(`cockroachdb/cockroach/pkg/kv/kvpb/gen: log$`),
stream.GrepNot(`cockroachdb/cockroach/pkg/util/log/gen: log$`),
stream.GrepNot(`cockroach/pkg/util/uuid: github\.com/satori/go\.uuid$`),
stream.GrepNot(`github.com/cockroachdb/cockroach/pkg/workload/debug: log$`),
), func(s string) {
pkgStr := strings.Split(s, ": ")
importingPkg, importedPkg := pkgStr[0], pkgStr[1]
Expand Down

0 comments on commit 63a0968

Please sign in to comment.