TmpDir returns a subdirectory in /tmp that can be used for test files.
(t *testing.T)
| 11 | |
| 12 | // TmpDir returns a subdirectory in /tmp that can be used for test files. |
| 13 | func TmpDir(t *testing.T) string { |
| 14 | // We use os.MkdirTemp as oposed to t.TempDir since the envbox container will |
| 15 | // chown some of the created directories here to root:root causing the cleanup |
| 16 | // function to fail once the test exits. |
| 17 | tmpdir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), "/", "_")) |
| 18 | require.NoError(t, err) |
| 19 | 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 | }) |
| 26 | return tmpdir |
| 27 | } |
| 28 | |
| 29 | func MkdirAll(t testing.TB, elem ...string) string { |
| 30 | t.Helper() |
no outgoing calls