diff --git a/internal/archiver/archiver_test.go b/internal/archiver/archiver_test.go index c3f72bf72..848822e29 100644 --- a/internal/archiver/archiver_test.go +++ b/internal/archiver/archiver_test.go @@ -1421,7 +1421,7 @@ func TestArchiverSnapshot(t *testing.T) { } TestEnsureSnapshot(t, repo, snapshotID, want) - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) // check that the snapshot contains the targets with absolute paths for i, target := range sn.Paths { @@ -1641,7 +1641,7 @@ func TestArchiverSnapshotSelect(t *testing.T) { } TestEnsureSnapshot(t, repo, snapshotID, want) - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) }) } } @@ -1866,7 +1866,7 @@ func TestArchiverParent(t *testing.T) { t.Logf("testfs: %v", testFS) } - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) }) } } @@ -2021,7 +2021,7 @@ func TestArchiverErrorReporting(t *testing.T) { } TestEnsureSnapshot(t, repo, snapshotID, want) - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) }) } } @@ -2384,7 +2384,7 @@ func TestMetadataChanged(t *testing.T) { // make sure the content matches TestEnsureFileContent(context.Background(), t, repo, "testfile", node3, files["testfile"].(TestFile)) - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) } func TestRacyFileTypeSwap(t *testing.T) { diff --git a/internal/checker/testing.go b/internal/checker/testing.go index d0014398f..89c307362 100644 --- a/internal/checker/testing.go +++ b/internal/checker/testing.go @@ -8,7 +8,7 @@ import ( ) // TestCheckRepo runs the checker on repo. -func TestCheckRepo(t testing.TB, repo restic.Repository, skipStructure bool) { +func TestCheckRepo(t testing.TB, repo restic.Repository) { chkr := New(repo, true) hints, errs := chkr.LoadIndex(context.TODO(), nil) @@ -33,23 +33,21 @@ func TestCheckRepo(t testing.TB, repo restic.Repository, skipStructure bool) { t.Error(err) } - if !skipStructure { - // structure - errChan = make(chan error) - go chkr.Structure(context.TODO(), nil, errChan) + // structure + errChan = make(chan error) + go chkr.Structure(context.TODO(), nil, errChan) - for err := range errChan { - t.Error(err) - } + for err := range errChan { + t.Error(err) + } - // unused blobs - blobs, err := chkr.UnusedBlobs(context.TODO()) - if err != nil { - t.Error(err) - } - if len(blobs) > 0 { - t.Errorf("unused blobs found: %v", blobs) - } + // unused blobs + blobs, err := chkr.UnusedBlobs(context.TODO()) + if err != nil { + t.Error(err) + } + if len(blobs) > 0 { + t.Errorf("unused blobs found: %v", blobs) } // read data diff --git a/internal/data/testing_test.go b/internal/data/testing_test.go index 6f6dec05b..35d32c04b 100644 --- a/internal/data/testing_test.go +++ b/internal/data/testing_test.go @@ -46,7 +46,7 @@ func TestCreateSnapshot(t *testing.T) { t.Fatalf("snapshot has zero tree ID") } - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) } func BenchmarkTestCreateSnapshot(t *testing.B) { diff --git a/internal/repository/index/master_index_test.go b/internal/repository/index/master_index_test.go index ad991b308..3e2c08cfe 100644 --- a/internal/repository/index/master_index_test.go +++ b/internal/repository/index/master_index_test.go @@ -402,7 +402,7 @@ func testIndexSave(t *testing.T, version uint) { })) rtest.Equals(t, 0, len(blobs), "saved index is missing blobs") - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) }) } } @@ -449,7 +449,7 @@ func testIndexSavePartial(t *testing.T, version uint) { // remove pack files to make check happy rtest.OK(t, restic.ParallelRemove(context.TODO(), unpacked, newPacks, restic.PackFile, nil, nil)) - checker.TestCheckRepo(t, repo, false) + checker.TestCheckRepo(t, repo) } func listPacks(t testing.TB, repo restic.Lister) restic.IDSet { diff --git a/internal/repository/prune_test.go b/internal/repository/prune_test.go index 2b6bdc2f2..6e5e05abf 100644 --- a/internal/repository/prune_test.go +++ b/internal/repository/prune_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - "github.com/restic/restic/internal/checker" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository/pack" "github.com/restic/restic/internal/restic" @@ -49,7 +48,7 @@ func testPrune(t *testing.T, opts repository.PruneOptions, errOnUnused bool) { rtest.OK(t, plan.Execute(context.TODO(), &progress.NoopPrinter{})) repo = repository.TestOpenBackend(t, be) - checker.TestCheckRepo(t, repo, true) + repository.TestCheckRepo(t, repo) if errOnUnused { existing := listBlobs(repo) @@ -181,7 +180,7 @@ func TestPruneSmall(t *testing.T) { // repopen repository repo = repository.TestOpenBackend(t, be) - checker.TestCheckRepo(t, repo, true) + repository.TestCheckRepo(t, repo) // load all blobs for blob := range keep { diff --git a/internal/repository/repair_index_test.go b/internal/repository/repair_index_test.go index 0fc89c79a..c6b095696 100644 --- a/internal/repository/repair_index_test.go +++ b/internal/repository/repair_index_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/restic/restic/internal/backend" - "github.com/restic/restic/internal/checker" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" @@ -36,7 +35,7 @@ func testRebuildIndex(t *testing.T, readAllPacks bool, damage func(t *testing.T, ReadAllPacks: readAllPacks, }, &progress.NoopPrinter{})) - checker.TestCheckRepo(t, repo, true) + repository.TestCheckRepo(t, repo) } func TestRebuildIndex(t *testing.T) { diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 3496b9a2d..fbce3b046 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -16,7 +16,6 @@ import ( "github.com/restic/restic/internal/backend/cache" "github.com/restic/restic/internal/backend/local" "github.com/restic/restic/internal/backend/mem" - "github.com/restic/restic/internal/checker" "github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" @@ -131,7 +130,7 @@ func testSavePackMerging(t *testing.T, targetPercentage int, expectedPacks int) })) rtest.Equals(t, expectedPacks, packs, "unexpected number of pack files") - checker.TestCheckRepo(t, repo, true) + repository.TestCheckRepo(t, repo) } func BenchmarkSaveAndEncrypt(t *testing.B) { diff --git a/internal/repository/testing.go b/internal/repository/testing.go index 988daba19..0661e93ea 100644 --- a/internal/repository/testing.go +++ b/internal/repository/testing.go @@ -162,3 +162,33 @@ func TestNewLock(_ *testing.T, repo *Repository, exclusive bool) (*restic.Lock, // TODO get rid of this test helper return restic.NewLock(context.TODO(), &internalRepository{repo}, exclusive) } + +// TestCheckRepo runs the checker on repo. +func TestCheckRepo(t testing.TB, repo restic.Repository) { + chkr := NewChecker(repo) + + hints, errs := chkr.LoadIndex(context.TODO(), nil) + if len(errs) != 0 { + t.Fatalf("errors loading index: %v", errs) + } + + if len(hints) != 0 { + t.Fatalf("errors loading index: %v", hints) + } + + // packs + errChan := make(chan error) + go chkr.Packs(context.TODO(), errChan) + + for err := range errChan { + t.Error(err) + } + + // read data + errChan = make(chan error) + go chkr.ReadData(context.TODO(), errChan) + + for err := range errChan { + t.Error(err) + } +}