Skip to content

Commit 9db34a0

Browse files
committed
cleanup tmpdir
1 parent b6eb32d commit 9db34a0

File tree

1 file changed

+7
-1
lines changed
  • integration/integrationtest

1 file changed

+7
-1
lines changed

integration/integrationtest/os.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ func TmpDir(t *testing.T) string {
1414
// We use os.MkdirTemp as oposed to t.TempDir since the envbox container will
1515
// chown some of the created directories here to root:root causing the cleanup
1616
// function to fail once the test exits.
17-
tmpdir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), "/", "_"))
17+
tmpdir, err := os.MkdirTemp(os.TempDir(), strings.ReplaceAll(t.Name(), "/", "_"))
1818
require.NoError(t, err)
1919
t.Logf("using tmpdir %s", tmpdir)
20+
t.Cleanup(func() {
21+
if !t.Failed() {
22+
// Could be useful in case of test failure.
23+
_ = os.RemoveAll(tmpdir)
24+
}
25+
})
2026
return tmpdir
2127
}
2228

0 commit comments

Comments
 (0)