diff --git a/.golangci.yml b/.golangci.yml index 9da63276a..3eca2593b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,6 +8,7 @@ linters: - unconvert - unused - whitespace + - usetesting exclusions: generated: lax presets: diff --git a/plugin/file/tree/print_test.go b/plugin/file/tree/print_test.go index 20ad37d9a..8c6c2b331 100644 --- a/plugin/file/tree/print_test.go +++ b/plugin/file/tree/print_test.go @@ -70,7 +70,7 @@ func TestPrint(t *testing.T) { */ - f, err := os.CreateTemp("", "print_test_tmp") + f, err := os.CreateTemp(t.TempDir(), "print_test_tmp") if err != nil { t.Error(err) } diff --git a/plugin/pkg/tls/tls_test.go b/plugin/pkg/tls/tls_test.go index a5635c177..b7ed109f7 100644 --- a/plugin/pkg/tls/tls_test.go +++ b/plugin/pkg/tls/tls_test.go @@ -1,7 +1,6 @@ package tls import ( - "os" "path/filepath" "testing" @@ -79,15 +78,8 @@ func TestNewTLSConfigFromArgs(t *testing.T) { func TestNewTLSConfigFromArgsWithRoot(t *testing.T) { cert, key, ca := getPEMFiles(t) - tempDir, err := os.MkdirTemp("", "go-test-pemfiles") - defer func() { - if err := os.RemoveAll(tempDir); err != nil { - t.Error("failed to clean up temporary directory", err) - } - }() - if err != nil { - t.Error("failed to create temporary directory", err) - } + tempDir := t.TempDir() + root := tempDir args := []string{cert, key, ca} for i := range args { diff --git a/plugin/root/root_test.go b/plugin/root/root_test.go index 27bdf84ad..f92912451 100644 --- a/plugin/root/root_test.go +++ b/plugin/root/root_test.go @@ -23,7 +23,7 @@ func TestRoot(t *testing.T) { nonExistingDir := filepath.Join(existingDirPath, "highly_unlikely_to_exist_dir") - existingFile, err := os.CreateTemp("", "root_test") + existingFile, err := os.CreateTemp(t.TempDir(), "root_test") if err != nil { t.Fatalf("BeforeTest: Failed to create temp file for testing! Error was: %v", err) }