2016-07-31 10:09:44 +00:00
|
|
|
package checker
|
|
|
|
|
|
|
|
import (
|
2017-06-04 09:16:55 +00:00
|
|
|
"context"
|
2016-09-03 11:34:04 +00:00
|
|
|
"restic"
|
2016-07-31 10:09:44 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestCheckRepo runs the checker on repo.
|
2016-09-03 11:34:04 +00:00
|
|
|
func TestCheckRepo(t testing.TB, repo restic.Repository) {
|
2016-07-31 10:09:44 +00:00
|
|
|
chkr := New(repo)
|
|
|
|
|
2017-06-04 09:16:55 +00:00
|
|
|
hints, errs := chkr.LoadIndex(context.TODO())
|
2016-07-31 10:09:44 +00:00
|
|
|
if len(errs) != 0 {
|
|
|
|
t.Fatalf("errors loading index: %v", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(hints) != 0 {
|
|
|
|
t.Fatalf("errors loading index: %v", hints)
|
|
|
|
}
|
|
|
|
|
2016-08-01 19:12:23 +00:00
|
|
|
// packs
|
2016-07-31 10:09:44 +00:00
|
|
|
errChan := make(chan error)
|
2017-06-04 09:16:55 +00:00
|
|
|
go chkr.Packs(context.TODO(), errChan)
|
2016-08-01 19:12:23 +00:00
|
|
|
|
|
|
|
for err := range errChan {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// structure
|
|
|
|
errChan = make(chan error)
|
2017-06-04 09:16:55 +00:00
|
|
|
go chkr.Structure(context.TODO(), errChan)
|
2016-07-31 10:09:44 +00:00
|
|
|
|
|
|
|
for err := range errChan {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2016-08-01 19:12:23 +00:00
|
|
|
// unused blobs
|
|
|
|
blobs := chkr.UnusedBlobs()
|
|
|
|
if len(blobs) > 0 {
|
|
|
|
t.Errorf("unused blobs found: %v", blobs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// read data
|
2016-07-31 10:09:44 +00:00
|
|
|
errChan = make(chan error)
|
2017-06-04 09:16:55 +00:00
|
|
|
go chkr.ReadData(context.TODO(), nil, errChan)
|
2016-07-31 10:09:44 +00:00
|
|
|
|
|
|
|
for err := range errChan {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|