TempDirectory returns an interesting temporary directory and cleans it up before test completes.
(tb testing.TB)
| 52 | // TempDirectory returns an interesting temporary directory and cleans it up before test |
| 53 | // completes. |
| 54 | func TempDirectory(tb testing.TB) string { |
| 55 | tb.Helper() |
| 56 | |
| 57 | d, err := GetInterestingTempDirectoryName() |
| 58 | if err != nil { |
| 59 | tb.Fatal(err) |
| 60 | } |
| 61 | |
| 62 | tb.Cleanup(func() { |
| 63 | if !tb.Failed() { |
| 64 | os.RemoveAll(d) //nolint:errcheck |
| 65 | } else { |
| 66 | tb.Logf("temporary files left in %v", d) |
| 67 | } |
| 68 | }) |
| 69 | |
| 70 | return d |
| 71 | } |
| 72 | |
| 73 | // TempDirectoryShort returns a short temporary directory and cleans it up before test |
| 74 | // completes. |