TempDirectoryShort returns a short temporary directory and cleans it up before test completes.
(tb testing.TB)
| 73 | // TempDirectoryShort returns a short temporary directory and cleans it up before test |
| 74 | // completes. |
| 75 | func TempDirectoryShort(tb testing.TB) string { |
| 76 | tb.Helper() |
| 77 | |
| 78 | d, err := os.MkdirTemp("", "kopia-test-"+time.Now().UTC().Format("20060102-150405")) //nolint:forbidigo |
| 79 | if err != nil { |
| 80 | tb.Fatal(errors.Wrap(err, "unable to create temp directory")) |
| 81 | } |
| 82 | |
| 83 | tb.Cleanup(func() { |
| 84 | if !tb.Failed() { |
| 85 | os.RemoveAll(d) //nolint:errcheck |
| 86 | } else { |
| 87 | tb.Logf("temporary files left in %v", d) |
| 88 | } |
| 89 | }) |
| 90 | |
| 91 | return d |
| 92 | } |
| 93 | |
| 94 | func getEnvVarBool(name string) bool { |
| 95 | s, err := strconv.ParseBool(os.Getenv(name)) |