index: rewrite MasterIndex load/save test to be independent of repository

This commit is contained in:
Michael Eischer 2024-05-19 15:48:25 +02:00
parent 447b486c20
commit fb59e00614

View file

@ -357,44 +357,25 @@ func TestIndexSave(t *testing.T) {
func testIndexSave(t *testing.T, version uint) { func testIndexSave(t *testing.T, version uint) {
repo := createFilledRepo(t, 3, version) repo := createFilledRepo(t, 3, version)
err := repo.LoadIndex(context.TODO(), nil) idx := index.NewMasterIndex()
if err != nil { rtest.OK(t, idx.Load(context.TODO(), repo, nil, nil))
t.Fatal(err) blobs := make(map[restic.PackedBlob]struct{})
} rtest.OK(t, idx.Each(context.TODO(), func(pb restic.PackedBlob) {
blobs[pb] = struct{}{}
}))
err = repo.SaveIndex(context.TODO(), nil, nil, restic.MasterIndexSaveOpts{}) rtest.OK(t, idx.Save(context.TODO(), repo, nil, nil, restic.MasterIndexSaveOpts{}))
if err != nil { idx = index.NewMasterIndex()
t.Fatalf("unable to save new index: %v", err) rtest.OK(t, idx.Load(context.TODO(), repo, nil, nil))
}
checker := checker.New(repo, false) rtest.OK(t, idx.Each(context.TODO(), func(pb restic.PackedBlob) {
err = checker.LoadSnapshots(context.TODO()) if _, ok := blobs[pb]; ok {
if err != nil { delete(blobs, pb)
t.Error(err) } else {
} t.Fatalf("unexpected blobs %v", pb)
hints, errs := checker.LoadIndex(context.TODO(), nil)
for _, h := range hints {
t.Logf("hint: %v\n", h)
}
for _, err := range errs {
t.Errorf("checker found error: %v", err)
}
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
errCh := make(chan error)
go checker.Structure(ctx, nil, errCh)
i := 0
for err := range errCh {
t.Errorf("checker returned error: %v", err)
i++
if i == 10 {
t.Errorf("more than 10 errors returned, skipping the rest")
cancel()
break
} }
} }))
rtest.Equals(t, 0, len(blobs), "saved index is missing blobs")
checker.TestCheckRepo(t, repo, false)
} }