2016-07-31 10:09:44 +00:00
|
|
|
package checker
|
|
|
|
|
|
|
|
import (
|
2017-06-04 09:16:55 +00:00
|
|
|
"context"
|
2016-07-31 10:09:44 +00:00
|
|
|
"testing"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
2017-07-24 15:42:25 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2016-07-31 10:09:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestCheckRepo runs the checker on repo.
|
2016-09-03 11:34:04 +00:00
|
|
|
func TestCheckRepo(t testing.TB, repo restic.Repository) {
|
2020-11-06 23:07:32 +00:00
|
|
|
chkr := New(repo, true)
|
2016-07-31 10:09:44 +00:00
|
|
|
|
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)
|
2020-12-05 23:07:45 +00:00
|
|
|
go chkr.Structure(context.TODO(), nil, 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
|
2020-11-06 22:41:04 +00:00
|
|
|
blobs := chkr.UnusedBlobs(context.TODO())
|
2016-08-01 19:12:23 +00:00
|
|
|
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)
|
2020-11-08 20:03:59 +00:00
|
|
|
go chkr.ReadData(context.TODO(), errChan)
|
2016-07-31 10:09:44 +00:00
|
|
|
|
|
|
|
for err := range errChan {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|