mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48:55 +00:00
fs: Add TestTempFile
This commit is contained in:
parent
ecbbd851a1
commit
bc68d55e94
@ -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 New Issue
Block a user