mirror of
https://github.com/octoleo/restic.git
synced 2024-11-23 21:27:34 +00:00
dc441c57a7
Tests should use a helper from internal/repository/testing.go to construct a Repository object.
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package index_test
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/restic/restic/internal/errors"
|
|
"github.com/restic/restic/internal/index"
|
|
"github.com/restic/restic/internal/repository"
|
|
"github.com/restic/restic/internal/restic"
|
|
rtest "github.com/restic/restic/internal/test"
|
|
)
|
|
|
|
var repoFixture = filepath.Join("..", "repository", "testdata", "test-repo.tar.gz")
|
|
|
|
func TestRepositoryForAllIndexes(t *testing.T) {
|
|
repo, cleanup := repository.TestFromFixture(t, repoFixture)
|
|
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
|
|
rtest.OK(t, index.ForAllIndexes(context.TODO(), repo, repo, func(id restic.ID, index *index.Index, oldFormat bool, err error) error {
|
|
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")
|
|
|
|
err := index.ForAllIndexes(context.TODO(), repo, repo, func(id restic.ID, index *index.Index, oldFormat bool, err error) error {
|
|
return iterErr
|
|
})
|
|
|
|
rtest.Equals(t, iterErr, err)
|
|
}
|