diff --git a/src/restic/checker/testing.go b/src/restic/checker/testing.go new file mode 100644 index 000000000..a2ac3345d --- /dev/null +++ b/src/restic/checker/testing.go @@ -0,0 +1,36 @@ +package checker + +import ( + "restic/repository" + "testing" +) + +// TestCheckRepo runs the checker on repo. +func TestCheckRepo(t testing.TB, repo *repository.Repository) { + chkr := New(repo) + + hints, errs := chkr.LoadIndex() + if len(errs) != 0 { + t.Fatalf("errors loading index: %v", errs) + } + + if len(hints) != 0 { + t.Fatalf("errors loading index: %v", hints) + } + + done := make(chan struct{}) + defer close(done) + errChan := make(chan error) + go chkr.Structure(errChan, done) + + for err := range errChan { + t.Error(err) + } + + errChan = make(chan error) + go chkr.ReadData(nil, errChan, done) + + for err := range errChan { + t.Error(err) + } +} diff --git a/src/restic/testing_test.go b/src/restic/testing_test.go index fa71038ac..8ec68b7ff 100644 --- a/src/restic/testing_test.go +++ b/src/restic/testing_test.go @@ -45,30 +45,5 @@ func TestCreateSnapshot(t *testing.T) { t.Fatalf("snapshot has zero tree ID") } - chkr := checker.New(repo) - - hints, errs := chkr.LoadIndex() - if len(errs) != 0 { - t.Fatalf("errors loading index: %v", errs) - } - - if len(hints) != 0 { - t.Fatalf("errors loading index: %v", hints) - } - - done := make(chan struct{}) - defer close(done) - errChan := make(chan error) - go chkr.Structure(errChan, done) - - for err := range errChan { - t.Error(err) - } - - errChan = make(chan error) - go chkr.ReadData(nil, errChan, done) - - for err := range errChan { - t.Error(err) - } + checker.TestCheckRepo(t, repo) }