forked from TrueCloudLab/restic
fs: Add TestTempFile
This commit is contained in:
parent
ecbbd851a1
commit
bc68d55e94
1 changed files with 20 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -41,3 +42,22 @@ func TestChdir(t testing.TB, dest string) (back func()) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestTempFile returns a new temporary file, which is removed when cleanup()
|
||||
// is called.
|
||||
func TestTempFile(t testing.TB, prefix string) (File, func()) {
|
||||
f, err := ioutil.TempFile("", prefix)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cleanup := func() {
|
||||
_ = f.Close()
|
||||
err = Remove(f.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return f, cleanup
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue