From 27faa3b84e659a3dc7fbf8639b77193387f79980 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Tue, 20 Jan 2026 10:33:54 +0100 Subject: [PATCH] test: replace os.MkdirTemp with t.TempDir() Use t.TempDir() which automatically cleans up the temporary directory when the test completes, eliminating the need for manual cleanup. Go 1.14 modernization pattern. Assisted-By: cagent Signed-off-by: David Gageot --- cmd/compose/options_test.go | 8 ++------ pkg/e2e/volumes_test.go | 5 +---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cmd/compose/options_test.go b/cmd/compose/options_test.go index 1686dfaf7..50f827521 100644 --- a/cmd/compose/options_test.go +++ b/cmd/compose/options_test.go @@ -213,10 +213,7 @@ func TestDisplayInterpolationVariables(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - // Create a temporary directory for the test - tmpDir, err := os.MkdirTemp("", "compose-test") - require.NoError(t, err) - defer func() { _ = os.RemoveAll(tmpDir) }() + tmpDir := t.TempDir() // Create a temporary compose file composeContent := ` @@ -230,8 +227,7 @@ services: - UNSET_VAR # optional without default ` composePath := filepath.Join(tmpDir, "docker-compose.yml") - err = os.WriteFile(composePath, []byte(composeContent), 0o644) - require.NoError(t, err) + require.NoError(t, os.WriteFile(composePath, []byte(composeContent), 0o644)) buf := new(bytes.Buffer) cli := mocks.NewMockCli(ctrl) diff --git a/pkg/e2e/volumes_test.go b/pkg/e2e/volumes_test.go index d018ed699..df138130d 100644 --- a/pkg/e2e/volumes_test.go +++ b/pkg/e2e/volumes_test.go @@ -19,7 +19,6 @@ package e2e import ( "fmt" "net/http" - "os" "path/filepath" "runtime" "strings" @@ -104,9 +103,7 @@ func TestProjectVolumeBind(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("Running on Windows. Skipping...") } - tmpDir, err := os.MkdirTemp("", projectName) - assert.NilError(t, err) - defer os.RemoveAll(tmpDir) //nolint + tmpDir := t.TempDir() c.RunDockerComposeCmd(t, "--project-name", projectName, "down")