2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-27 15:26:37 +00:00
restic/internal/checker/testing.go

63 lines
1.1 KiB
Go
Raw Normal View History

package checker
import (
2017-06-04 09:16:55 +00:00
"context"
"testing"
2017-07-23 12:21:03 +00:00
2017-07-24 15:42:25 +00:00
"github.com/restic/restic/internal/restic"
)
// TestCheckRepo runs the checker on repo.
func TestCheckRepo(t testing.TB, repo restic.Repository, skipStructure bool) {
chkr := New(repo, true)
2023-10-01 17:48:56 +00:00
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)
}
2021-11-07 21:33:44 +00:00
err := chkr.LoadSnapshots(context.TODO())
if err != nil {
t.Error(err)
}
2016-08-01 19:12:23 +00:00
// packs
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)
}
if !skipStructure {
// structure
errChan = make(chan error)
go chkr.Structure(context.TODO(), nil, errChan)
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)
}
2016-08-01 19:12:23 +00:00
}
// read data
errChan = make(chan error)
go chkr.ReadData(context.TODO(), errChan)
for err := range errChan {
t.Error(err)
}
}