From 5c32ae15c2b32ca37ff097ec5745da4e77039953 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 31 Jul 2016 12:09:44 +0200 Subject: [PATCH] Move test checking repo code to checker package --- src/restic/checker/testing.go | 36 +++++++++++++++++++++++++++++++++++ src/restic/testing_test.go | 27 +------------------------- 2 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 src/restic/checker/testing.go 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) }