mirror of
https://github.com/restic/restic.git
synced 2025-10-10 12:10:26 +00:00
repository: Remove empty cleanup functions in tests
TestRepository and its variants always returned no-op cleanup functions. If they ever do need to do cleanup, using testing.T.Cleanup is easier than passing these functions around.
This commit is contained in:
@@ -19,7 +19,7 @@ func FuzzSaveLoadBlob(f *testing.F) {
|
||||
}
|
||||
|
||||
id := restic.Hash(blob)
|
||||
repo, _ := TestRepositoryWithBackend(t, mem.New(), 2)
|
||||
repo := TestRepositoryWithBackend(t, mem.New(), 2)
|
||||
|
||||
var wg errgroup.Group
|
||||
repo.StartPackUploader(context.TODO(), &wg)
|
||||
|
@@ -223,8 +223,7 @@ func TestRepack(t *testing.T) {
|
||||
}
|
||||
|
||||
func testRepack(t *testing.T, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
|
||||
seed := time.Now().UnixNano()
|
||||
rand.Seed(seed)
|
||||
@@ -302,10 +301,8 @@ func (r oneConnectionRepo) Connections() uint {
|
||||
}
|
||||
|
||||
func testRepackCopy(t *testing.T, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
dstRepo, dstCleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer dstCleanup()
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
dstRepo := repository.TestRepositoryWithVersion(t, version)
|
||||
|
||||
// test with minimal possible connection count
|
||||
repoWrapped := &oneConnectionRepo{repo}
|
||||
@@ -349,8 +346,7 @@ func TestRepackWrongBlob(t *testing.T) {
|
||||
}
|
||||
|
||||
func testRepackWrongBlob(t *testing.T, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
|
||||
seed := time.Now().UnixNano()
|
||||
rand.Seed(seed)
|
||||
@@ -375,8 +371,7 @@ func TestRepackBlobFallback(t *testing.T) {
|
||||
}
|
||||
|
||||
func testRepackBlobFallback(t *testing.T, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
|
||||
seed := time.Now().UnixNano()
|
||||
rand.Seed(seed)
|
||||
|
@@ -35,8 +35,7 @@ func TestSave(t *testing.T) {
|
||||
}
|
||||
|
||||
func testSave(t *testing.T, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
|
||||
for _, size := range testSizes {
|
||||
data := make([]byte, size)
|
||||
@@ -77,8 +76,7 @@ func TestSaveFrom(t *testing.T) {
|
||||
}
|
||||
|
||||
func testSaveFrom(t *testing.T, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
|
||||
for _, size := range testSizes {
|
||||
data := make([]byte, size)
|
||||
@@ -117,9 +115,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkSaveAndEncrypt(t *testing.B, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
size := 4 << 20 // 4MiB
|
||||
|
||||
data := make([]byte, size)
|
||||
@@ -145,9 +141,7 @@ func TestLoadBlob(t *testing.T) {
|
||||
}
|
||||
|
||||
func testLoadBlob(t *testing.T, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestRepositoryWithVersion(t, version)
|
||||
length := 1000000
|
||||
buf := crypto.NewBlobBuffer(length)
|
||||
_, err := io.ReadFull(rnd, buf)
|
||||
@@ -181,9 +175,7 @@ func BenchmarkLoadBlob(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkLoadBlob(b *testing.B, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(b, version)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestRepositoryWithVersion(b, version)
|
||||
length := 1000000
|
||||
buf := crypto.NewBlobBuffer(length)
|
||||
_, err := io.ReadFull(rnd, buf)
|
||||
@@ -224,9 +216,7 @@ func BenchmarkLoadUnpacked(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkLoadUnpacked(b *testing.B, version uint) {
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(b, version)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestRepositoryWithVersion(b, version)
|
||||
length := 1000000
|
||||
buf := crypto.NewBlobBuffer(length)
|
||||
_, err := io.ReadFull(rnd, buf)
|
||||
@@ -345,9 +335,7 @@ func BenchmarkLoadIndex(b *testing.B) {
|
||||
func benchmarkLoadIndex(b *testing.B, version uint) {
|
||||
repository.TestUseLowSecurityKDFParameters(b)
|
||||
|
||||
repo, cleanup := repository.TestRepositoryWithVersion(b, version)
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestRepositoryWithVersion(b, version)
|
||||
idx := index.NewIndex()
|
||||
|
||||
for i := 0; i < 5000; i++ {
|
||||
@@ -398,10 +386,7 @@ func TestRepositoryIncrementalIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func testRepositoryIncrementalIndex(t *testing.T, version uint) {
|
||||
r, cleanup := repository.TestRepositoryWithVersion(t, version)
|
||||
defer cleanup()
|
||||
|
||||
repo := r.(*repository.Repository)
|
||||
repo := repository.TestRepositoryWithVersion(t, version).(*repository.Repository)
|
||||
|
||||
index.IndexFull = func(*index.Index, bool) bool { return true }
|
||||
|
||||
|
@@ -33,8 +33,8 @@ func TestUseLowSecurityKDFParameters(t logger) {
|
||||
}
|
||||
|
||||
// TestBackend returns a fully configured in-memory backend.
|
||||
func TestBackend(t testing.TB) (be restic.Backend, cleanup func()) {
|
||||
return mem.New(), func() {}
|
||||
func TestBackend(t testing.TB) restic.Backend {
|
||||
return mem.New()
|
||||
}
|
||||
|
||||
const TestChunkerPol = chunker.Pol(0x3DA3358B4DC173)
|
||||
@@ -42,14 +42,13 @@ const TestChunkerPol = chunker.Pol(0x3DA3358B4DC173)
|
||||
// TestRepositoryWithBackend returns a repository initialized with a test
|
||||
// password. If be is nil, an in-memory backend is used. A constant polynomial
|
||||
// is used for the chunker and low-security test parameters.
|
||||
func TestRepositoryWithBackend(t testing.TB, be restic.Backend, version uint) (r restic.Repository, cleanup func()) {
|
||||
func TestRepositoryWithBackend(t testing.TB, be restic.Backend, version uint) restic.Repository {
|
||||
t.Helper()
|
||||
TestUseLowSecurityKDFParameters(t)
|
||||
restic.TestDisableCheckPolynomial(t)
|
||||
|
||||
var beCleanup func()
|
||||
if be == nil {
|
||||
be, beCleanup = TestBackend(t)
|
||||
be = TestBackend(t)
|
||||
}
|
||||
|
||||
repo, err := New(be, Options{})
|
||||
@@ -63,23 +62,19 @@ func TestRepositoryWithBackend(t testing.TB, be restic.Backend, version uint) (r
|
||||
t.Fatalf("TestRepository(): initialize repo failed: %v", err)
|
||||
}
|
||||
|
||||
return repo, func() {
|
||||
if beCleanup != nil {
|
||||
beCleanup()
|
||||
}
|
||||
}
|
||||
return repo
|
||||
}
|
||||
|
||||
// TestRepository returns a repository initialized with a test password on an
|
||||
// in-memory backend. When the environment variable RESTIC_TEST_REPO is set to
|
||||
// a non-existing directory, a local backend is created there and this is used
|
||||
// instead. The directory is not removed, but left there for inspection.
|
||||
func TestRepository(t testing.TB) (r restic.Repository, cleanup func()) {
|
||||
func TestRepository(t testing.TB) restic.Repository {
|
||||
t.Helper()
|
||||
return TestRepositoryWithVersion(t, 0)
|
||||
}
|
||||
|
||||
func TestRepositoryWithVersion(t testing.TB, version uint) (r restic.Repository, cleanup func()) {
|
||||
func TestRepositoryWithVersion(t testing.TB, version uint) restic.Repository {
|
||||
t.Helper()
|
||||
dir := os.Getenv("RESTIC_TEST_REPO")
|
||||
if dir != "" {
|
||||
|
Reference in New Issue
Block a user