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 <david.gageot@docker.com>
This commit is contained in:
David Gageot 2026-01-20 10:33:54 +01:00 committed by Guillaume Lours
parent bcc0401e0e
commit 27faa3b84e
2 changed files with 3 additions and 10 deletions

View file

@ -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)

View file

@ -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")