MCPcopy
hub / github.com/kopia/kopia / TempDirectoryShort

Function TempDirectoryShort

internal/testutil/tmpdir.go:75–92  ·  view source on GitHub ↗

TempDirectoryShort returns a short temporary directory and cleans it up before test completes.

(tb testing.TB)

Source from the content-addressed store, hash-verified

73// TempDirectoryShort returns a short temporary directory and cleans it up before test
74// completes.
75func 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
94func getEnvVarBool(name string) bool {
95 s, err := strconv.ParseBool(os.Getenv(name))

Callers 2

TestServerControlUDSFunction · 0.92
TestFileStorageLongPathFunction · 0.92

Calls 6

HelperMethod · 0.80
NowMethod · 0.80
LogfMethod · 0.80
FormatMethod · 0.65
CleanupMethod · 0.65
RemoveAllMethod · 0.45

Tested by 2

TestServerControlUDSFunction · 0.74
TestFileStorageLongPathFunction · 0.74