From cf48f126165ae466f9c3464caaa62fe4afb1dd66 Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Wed, 9 Oct 2024 14:53:46 -0500 Subject: [PATCH] lint: fix `TestForbiddenImports` 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 #132262) Closes #132258 Epic: none Release note: None --- pkg/testutils/lint/lint_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/testutils/lint/lint_test.go b/pkg/testutils/lint/lint_test.go index 4597e0f33639..447f3889a4cb 100644 --- a/pkg/testutils/lint/lint_test.go +++ b/pkg/testutils/lint/lint_test.go @@ -1546,12 +1546,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 @@ -1583,6 +1590,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]