2022-06-12 12:43:43 +00:00
|
|
|
package index_test
|
2020-12-18 19:25:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-06-12 12:43:43 +00:00
|
|
|
"path/filepath"
|
2020-12-18 19:25:30 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/restic/restic/internal/errors"
|
2022-06-12 12:43:43 +00:00
|
|
|
"github.com/restic/restic/internal/index"
|
2020-12-18 19:25:30 +00:00
|
|
|
"github.com/restic/restic/internal/repository"
|
|
|
|
"github.com/restic/restic/internal/restic"
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
)
|
|
|
|
|
2022-06-12 12:43:43 +00:00
|
|
|
var repoFixture = filepath.Join("..", "repository", "testdata", "test-repo.tar.gz")
|
|
|
|
|
2020-12-18 19:25:30 +00:00
|
|
|
func TestRepositoryForAllIndexes(t *testing.T) {
|
2024-02-24 20:45:24 +00:00
|
|
|
repo, cleanup := repository.TestFromFixture(t, repoFixture)
|
2020-12-18 19:25:30 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
expectedIndexIDs := restic.NewIDSet()
|
|
|
|
rtest.OK(t, repo.List(context.TODO(), restic.IndexFile, func(id restic.ID, size int64) error {
|
|
|
|
expectedIndexIDs.Insert(id)
|
|
|
|
return nil
|
|
|
|
}))
|
|
|
|
|
|
|
|
// check that all expected indexes are loaded without errors
|
|
|
|
indexIDs := restic.NewIDSet()
|
|
|
|
var indexErr error
|
2023-10-01 11:05:56 +00:00
|
|
|
rtest.OK(t, index.ForAllIndexes(context.TODO(), repo, repo, func(id restic.ID, index *index.Index, oldFormat bool, err error) error {
|
2020-12-18 19:25:30 +00:00
|
|
|
if err != nil {
|
|
|
|
indexErr = err
|
|
|
|
}
|
|
|
|
indexIDs.Insert(id)
|
|
|
|
return nil
|
|
|
|
}))
|
|
|
|
rtest.OK(t, indexErr)
|
|
|
|
rtest.Equals(t, expectedIndexIDs, indexIDs)
|
|
|
|
|
|
|
|
// must failed with the returned error
|
|
|
|
iterErr := errors.New("error to pass upwards")
|
|
|
|
|
2023-10-01 11:05:56 +00:00
|
|
|
err := index.ForAllIndexes(context.TODO(), repo, repo, func(id restic.ID, index *index.Index, oldFormat bool, err error) error {
|
2020-12-18 19:25:30 +00:00
|
|
|
return iterErr
|
|
|
|
})
|
|
|
|
|
|
|
|
rtest.Equals(t, iterErr, err)
|
|
|
|
}
|