From 68480dc11dc52874485598afade9056214af63c9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Jul 2025 12:48:59 +0200 Subject: [PATCH] integration-cli: remove createTmpFile utility Signed-off-by: Sebastiaan van Stijn --- integration-cli/docker_cli_run_test.go | 17 ++++++++++------- integration-cli/docker_utils_test.go | 13 ------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 7f535fcfc4..cfc61c9eb2 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2941,10 +2941,11 @@ func (s *DockerCLIRunSuite) TestRunNetworkFilesBindMount(c *testing.T) { // Not applicable on Windows as uses Unix specific functionality testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) - expected := "test123" + tmpDir := c.TempDir() + filename := filepath.Join(tmpDir, "testfile") - filename := createTmpFile(c, expected) - defer os.Remove(filename) + const expected = "test123" + assert.NilError(c, os.WriteFile(filename, []byte(expected), 0o644)) // #nosec G302 -- for user namespaced test runs, the temp file must be accessible to unprivileged root if err := os.Chmod(filename, 0o646); err != nil { @@ -2965,8 +2966,9 @@ func (s *DockerCLIRunSuite) TestRunNetworkFilesBindMountRO(c *testing.T) { // Not applicable on Windows as uses Unix specific functionality testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) - filename := createTmpFile(c, "test123") - defer os.Remove(filename) + tmpDir := c.TempDir() + filename := filepath.Join(tmpDir, "testfile") + assert.NilError(c, os.WriteFile(filename, []byte("test123"), 0o644)) // #nosec G302 -- for user namespaced test runs, the temp file must be accessible to unprivileged root if err := os.Chmod(filename, 0o646); err != nil { @@ -2987,8 +2989,9 @@ func (s *DockerCLIRunSuite) TestRunNetworkFilesBindMountROFilesystem(c *testing. // Not applicable on Windows as uses Unix specific functionality testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux, UserNamespaceROMount) - filename := createTmpFile(c, "test123") - defer os.Remove(filename) + tmpDir := c.TempDir() + filename := filepath.Join(tmpDir, "testfile") + assert.NilError(c, os.WriteFile(filename, []byte("test123"), 0o644)) // #nosec G302 -- for user namespaced test runs, the temp file must be accessible to unprivileged root if err := os.Chmod(filename, 0o646); err != nil { diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index 428c48bb93..f5f74a5ade 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -271,19 +271,6 @@ func appendBaseEnv(isTLS bool, env ...string) []string { return env } -func createTmpFile(t *testing.T, content string) string { - t.Helper() - f, err := os.CreateTemp("", "testfile") - assert.NilError(t, err) - - filename := f.Name() - - err = os.WriteFile(filename, []byte(content), 0o644) - assert.NilError(t, err) - - return filename -} - // waitInspect will wait for the specified container to have the specified string // in the inspect output. It will wait until the specified timeout (in seconds) // is reached.