From 58c7d7aff2e5c4462a8e9ba914792d186e17a7bc Mon Sep 17 00:00:00 2001 From: Anders Eknert Date: Wed, 19 Feb 2025 10:29:17 +0100 Subject: [PATCH] Bump golangci-lint -> 1.64.5 (#7374) Also: - Replace deprecated tenv linter with usetesting, and address the issues it reported (nice!) Signed-off-by: Anders Eknert --- .golangci.yaml | 2 +- Makefile | 2 +- cmd/build_test.go | 19 +++----------- cmd/exec_test.go | 2 +- cmd/internal/exec/exec_test.go | 2 +- v1/plugins/rest/aws_test.go | 2 +- v1/plugins/rest/rest_test.go | 4 +-- v1/repl/repl_test.go | 26 ++----------------- .../distributedtracing_test.go | 2 +- v1/topdown/http_test.go | 2 +- 10 files changed, 14 insertions(+), 49 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index d371efdf69..ce14ebccd3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -167,7 +167,7 @@ linters: - goimports - unused - misspell - - tenv + - usetesting - typecheck - staticcheck - gosimple diff --git a/Makefile b/Makefile index b70ff80515..1f7d535c48 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ ifeq ($(WASM_ENABLED),1) GO_TAGS = -tags=opa_wasm endif -GOLANGCI_LINT_VERSION := v1.60.1 +GOLANGCI_LINT_VERSION := v1.64.5 YAML_LINT_VERSION := 0.29.0 YAML_LINT_FORMAT ?= auto diff --git a/cmd/build_test.go b/cmd/build_test.go index 60bb2f3fa9..4bfef8a629 100644 --- a/cmd/build_test.go +++ b/cmd/build_test.go @@ -2831,17 +2831,9 @@ foo contains __local1__1 if { // There's probably some common utilities that could be extracted at some point but for now this code is // local to the test until we need to reuse it elsewhere. func TestBuildWithFollowSymlinks(t *testing.T) { - rootDir, err := os.MkdirTemp("", "build-follow-symlinks") - if err != nil { - t.Fatal(err) - } - defer func() { - if err := os.RemoveAll(rootDir); err != nil { - t.Fatal(err) - } - }() + rootDir := t.TempDir() bundleDir := path.Join(rootDir, "bundle") - err = os.Mkdir(bundleDir, 0777) + err := os.Mkdir(bundleDir, 0777) if err != nil { t.Fatal(err) } @@ -2944,17 +2936,14 @@ func TestBuildWithFollowSymlinks(t *testing.T) { // This test uses a local tmp filesystem to create a directory with a local file in the bundle directory, and // verifies that the built bundle contains the files from the symlinked directory. func TestBuildWithFollowSymlinksEntireDir(t *testing.T) { - rootDir, err := os.MkdirTemp("", "build-follow-symlinks-dir") - if err != nil { - t.Fatal(err) - } + rootDir := t.TempDir() defer func() { if err := os.RemoveAll(rootDir); err != nil { t.Fatal(err) } }() bundleDir := path.Join(rootDir, "src") - err = os.Mkdir(bundleDir, 0777) + err := os.Mkdir(bundleDir, 0777) if err != nil { t.Fatal(err) } diff --git a/cmd/exec_test.go b/cmd/exec_test.go index d02db6ea0f..3eb0766d72 100644 --- a/cmd/exec_test.go +++ b/cmd/exec_test.go @@ -1420,7 +1420,7 @@ func TestExecWithInvalidInputOptions(t *testing.T) { params.BundlePaths = []string{dir + "/bundle/"} if tt.stdIn { params.StdIn = true - tempFile, err := os.CreateTemp("", "test") + tempFile, err := os.CreateTemp(t.TempDir(), "test") if err != nil { t.Fatalf("unexpected error creating temp file: %q", err.Error()) } diff --git a/cmd/internal/exec/exec_test.go b/cmd/internal/exec/exec_test.go index db48d89dd6..38e49979d9 100644 --- a/cmd/internal/exec/exec_test.go +++ b/cmd/internal/exec/exec_test.go @@ -205,7 +205,7 @@ func TestExec(t *testing.T) { params.FailNonEmpty = true if tt.stdIn { params.StdIn = true - tempFile, err := os.CreateTemp("", "test") + tempFile, err := os.CreateTemp(t.TempDir(), "test") if err != nil { t.Fatalf("unexpected error creating temp file: %q", err.Error()) } diff --git a/v1/plugins/rest/aws_test.go b/v1/plugins/rest/aws_test.go index 76c3b26a92..57178dce27 100644 --- a/v1/plugins/rest/aws_test.go +++ b/v1/plugins/rest/aws_test.go @@ -361,7 +361,7 @@ func TestMetadataCredentialService(t *testing.T) { test.WithTempFS(nil, func(path string) { // wrong path: bad file token t.Setenv(ecsFullPathEnvVar, "fullPath") - os.Setenv(ecsAuthorizationTokenFileEnvVar, filepath.Join(path, "bad-file")) + t.Setenv(ecsAuthorizationTokenFileEnvVar, filepath.Join(path, "bad-file")) _, err = cs.credentials(context.Background()) assertErr("failed to read ECS metadata authorization token from file", err, t) os.Unsetenv(ecsFullPathEnvVar) diff --git a/v1/plugins/rest/rest_test.go b/v1/plugins/rest/rest_test.go index 7c5f182775..656515ee40 100644 --- a/v1/plugins/rest/rest_test.go +++ b/v1/plugins/rest/rest_test.go @@ -1927,8 +1927,6 @@ func TestS3SigningMultiCredentialProvider(t *testing.T) { } func TestAWSCredentialServiceChain(t *testing.T) { - t.Parallel() - tests := []struct { name string input string @@ -1980,7 +1978,7 @@ func TestAWSCredentialServiceChain(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { for key, val := range tc.env { - _ = os.Setenv(key, val) + t.Setenv(key, val) } t.Cleanup(func() { diff --git a/v1/repl/repl_test.go b/v1/repl/repl_test.go index abe239986b..47d015c9a1 100644 --- a/v1/repl/repl_test.go +++ b/v1/repl/repl_test.go @@ -295,18 +295,7 @@ func TestDumpPath(t *testing.T) { var buffer bytes.Buffer repl := newRepl(store, &buffer) - dir, err := os.MkdirTemp("", "dump-path-test") - if err != nil { - t.Fatal(err) - } - - t.Cleanup(func() { - err := os.RemoveAll(dir) - if err != nil { - t.Errorf("error cleaning up with RemoveAll(): %v", err) - } - }) - file := filepath.Join(dir, "tmpfile") + file := filepath.Join(t.TempDir(), "tmpfile") if err := repl.OneShot(ctx, "dump "+file); err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -342,18 +331,7 @@ func TestDumpPathCaseSensitive(t *testing.T) { var buffer bytes.Buffer repl := newRepl(store, &buffer) - dir, err := os.MkdirTemp("", "DumpPathCaseSensitiveTest") - if err != nil { - t.Fatal(err) - } - - t.Cleanup(func() { - err := os.RemoveAll(dir) - if err != nil { - t.Errorf("error cleaning up with RemoveAll(): %v", err) - } - }) - file := filepath.Join(dir, "tmpfile") + file := filepath.Join(t.TempDir(), "tmpfile") if err := repl.OneShot(ctx, "dump "+file); err != nil { t.Fatalf("Unexpected error: %v", err) } diff --git a/v1/test/e2e/distributedtracing/distributedtracing_test.go b/v1/test/e2e/distributedtracing/distributedtracing_test.go index 93df2911f4..307342da4e 100644 --- a/v1/test/e2e/distributedtracing/distributedtracing_test.go +++ b/v1/test/e2e/distributedtracing/distributedtracing_test.go @@ -607,7 +607,7 @@ allow if { input.path = ["health"] }`) - tmpfile, err := os.CreateTemp("", "authz.*.rego") + tmpfile, err := os.CreateTemp(t.TempDir(), "authz.*.rego") if err != nil { t.Fatal(err) } diff --git a/v1/topdown/http_test.go b/v1/topdown/http_test.go index 79600e2452..a21537611a 100644 --- a/v1/topdown/http_test.go +++ b/v1/topdown/http_test.go @@ -3554,7 +3554,7 @@ func TestSocketHTTPGetRequest(t *testing.T) { people = append(people, Person{ID: "1", Firstname: "John"}) // Create a local socket - tmpF, err := os.CreateTemp("", "") + tmpF, err := os.CreateTemp(t.TempDir(), "") if err != nil { t.Fatal(err) }