forked from TrueCloudLab/restic
test: Add TempDir() helper
This commit is contained in:
parent
c8eea49909
commit
80a864c52c
1 changed files with 18 additions and 0 deletions
|
@ -170,3 +170,21 @@ func RemoveAll(t testing.TB, path string) {
|
||||||
ResetReadOnly(t, path)
|
ResetReadOnly(t, path)
|
||||||
OK(t, os.RemoveAll(path))
|
OK(t, os.RemoveAll(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TempDir returns a temporary directory that is removed when cleanup is
|
||||||
|
// called, except if TestCleanupTempDirs is set to false.
|
||||||
|
func TempDir(t testing.TB) (path string, cleanup func()) {
|
||||||
|
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempdir, func() {
|
||||||
|
if !TestCleanupTempDirs {
|
||||||
|
t.Logf("leaving temporary directory %v used for test", tempdir)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoveAll(t, tempdir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue