From 9db34a05913a2e97e6919b0e5abe065ab1335efa Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Wed, 27 Nov 2024 15:16:23 +0000 Subject: [PATCH 1/2] cleanup tmpdir --- integration/integrationtest/os.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/integration/integrationtest/os.go b/integration/integrationtest/os.go index 45aacd7..61d4598 100644 --- a/integration/integrationtest/os.go +++ b/integration/integrationtest/os.go @@ -14,9 +14,15 @@ func TmpDir(t *testing.T) string { // We use os.MkdirTemp as oposed to t.TempDir since the envbox container will // chown some of the created directories here to root:root causing the cleanup // function to fail once the test exits. - tmpdir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), "/", "_")) + tmpdir, err := os.MkdirTemp(os.TempDir(), strings.ReplaceAll(t.Name(), "/", "_")) require.NoError(t, err) t.Logf("using tmpdir %s", tmpdir) + t.Cleanup(func() { + if !t.Failed() { + // Could be useful in case of test failure. + _ = os.RemoveAll(tmpdir) + } + }) return tmpdir } From bc946cf2e3e2ba6913868a69fac9822aa1624865 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Wed, 27 Nov 2024 15:24:23 +0000 Subject: [PATCH 2/2] fix: fix test leaking file --- integration/docker_test.go | 3 +++ integration/integrationtest/os.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/integration/docker_test.go b/integration/docker_test.go index 1419ff5..9f88b09 100644 --- a/integration/docker_test.go +++ b/integration/docker_test.go @@ -425,6 +425,9 @@ func TestDocker(t *testing.T) { HostKeyPath: regKeyPath, Image: integrationtest.UbuntuImage, TLSPort: strconv.Itoa(registryAddr.Port), + PasswordDir: dir, + Username: "user", + Password: "password", }) envs := []string{ diff --git a/integration/integrationtest/os.go b/integration/integrationtest/os.go index 61d4598..dc13318 100644 --- a/integration/integrationtest/os.go +++ b/integration/integrationtest/os.go @@ -14,7 +14,7 @@ func TmpDir(t *testing.T) string { // We use os.MkdirTemp as oposed to t.TempDir since the envbox container will // chown some of the created directories here to root:root causing the cleanup // function to fail once the test exits. - tmpdir, err := os.MkdirTemp(os.TempDir(), strings.ReplaceAll(t.Name(), "/", "_")) + tmpdir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), "/", "_")) require.NoError(t, err) t.Logf("using tmpdir %s", tmpdir) t.Cleanup(func() {