mirror of
https://github.com/restic/restic.git
synced 2025-12-03 20:11:52 +00:00
test: Use testing.T.Cleanup to remove tempdirs
This commit is contained in:
14
internal/cache/backend_test.go
vendored
14
internal/cache/backend_test.go
vendored
@@ -57,10 +57,7 @@ func randomData(n int) (restic.Handle, []byte) {
|
||||
|
||||
func TestBackend(t *testing.T) {
|
||||
be := mem.New()
|
||||
|
||||
c, cleanup := TestNewCache(t)
|
||||
defer cleanup()
|
||||
|
||||
c := TestNewCache(t)
|
||||
wbe := c.Wrap(be)
|
||||
|
||||
h, data := randomData(5234142)
|
||||
@@ -128,10 +125,7 @@ func (be loadErrorBackend) Load(ctx context.Context, h restic.Handle, length int
|
||||
|
||||
func TestErrorBackend(t *testing.T) {
|
||||
be := mem.New()
|
||||
|
||||
c, cleanup := TestNewCache(t)
|
||||
defer cleanup()
|
||||
|
||||
c := TestNewCache(t)
|
||||
h, data := randomData(5234142)
|
||||
|
||||
// save directly in backend
|
||||
@@ -174,9 +168,7 @@ func TestErrorBackend(t *testing.T) {
|
||||
|
||||
func TestBackendRemoveBroken(t *testing.T) {
|
||||
be := mem.New()
|
||||
|
||||
c, cleanup := TestNewCache(t)
|
||||
defer cleanup()
|
||||
c := TestNewCache(t)
|
||||
|
||||
h, data := randomData(5234142)
|
||||
// save directly in backend
|
||||
|
||||
10
internal/cache/file_test.go
vendored
10
internal/cache/file_test.go
vendored
@@ -87,8 +87,7 @@ func TestFiles(t *testing.T) {
|
||||
t.Logf("seed is %v", seed)
|
||||
rand.Seed(seed)
|
||||
|
||||
c, cleanup := TestNewCache(t)
|
||||
defer cleanup()
|
||||
c := TestNewCache(t)
|
||||
|
||||
var tests = []restic.FileType{
|
||||
restic.SnapshotFile,
|
||||
@@ -140,8 +139,7 @@ func TestFileLoad(t *testing.T) {
|
||||
t.Logf("seed is %v", seed)
|
||||
rand.Seed(seed)
|
||||
|
||||
c, cleanup := TestNewCache(t)
|
||||
defer cleanup()
|
||||
c := TestNewCache(t)
|
||||
|
||||
// save about 5 MiB of data in the cache
|
||||
data := test.Random(rand.Int(), 5234142)
|
||||
@@ -223,10 +221,8 @@ func TestFileSaveConcurrent(t *testing.T) {
|
||||
|
||||
const nproc = 40
|
||||
|
||||
c, cleanup := TestNewCache(t)
|
||||
defer cleanup()
|
||||
|
||||
var (
|
||||
c = TestNewCache(t)
|
||||
data = test.Random(1, 10000)
|
||||
g errgroup.Group
|
||||
id restic.ID
|
||||
|
||||
6
internal/cache/testing.go
vendored
6
internal/cache/testing.go
vendored
@@ -9,12 +9,12 @@ import (
|
||||
|
||||
// TestNewCache returns a cache in a temporary directory which is removed when
|
||||
// cleanup is called.
|
||||
func TestNewCache(t testing.TB) (*Cache, func()) {
|
||||
dir, cleanup := test.TempDir(t)
|
||||
func TestNewCache(t testing.TB) *Cache {
|
||||
dir := test.TempDir(t)
|
||||
t.Logf("created new cache at %v", dir)
|
||||
cache, err := New(restic.NewRandomID().String(), dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return cache, cleanup
|
||||
return cache
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user