From a12c5f1d3725a52afe003a7d22904008b6fb3cf7 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 7 Nov 2020 18:53:59 +0100 Subject: [PATCH] repository: move otherwise unused LoadIndex to tests --- internal/repository/repository.go | 14 -------------- internal/repository/repository_test.go | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/internal/repository/repository.go b/internal/repository/repository.go index c534fb565..a0d27cc3f 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -595,20 +595,6 @@ func (r *Repository) PrepareCache(indexIDs restic.IDSet) error { return nil } -// LoadIndex loads the index id from backend and returns it. -func LoadIndex(ctx context.Context, repo restic.Repository, id restic.ID) (*Index, error) { - buf, err := repo.LoadAndDecrypt(ctx, nil, restic.IndexFile, id) - if err != nil { - return nil, err - } - - idx, oldFormat, err := DecodeIndex(buf, id) - if oldFormat { - fmt.Fprintf(os.Stderr, "index %v has old format\n", id.Str()) - } - return idx, err -} - // SearchKey finds a key with the supplied password, afterwards the config is // read and parsed. It tries at most maxKeys key files in the repo. func (r *Repository) SearchKey(ctx context.Context, password string, maxKeys int, keyHint string) error { diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 1e485320d..22a424556 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -4,8 +4,10 @@ import ( "bytes" "context" "crypto/sha256" + "fmt" "io" "math/rand" + "os" "path/filepath" "testing" "time" @@ -293,6 +295,20 @@ func TestRepositoryLoadIndex(t *testing.T) { rtest.OK(t, repo.LoadIndex(context.TODO())) } +// loadIndex loads the index id from backend and returns it. +func loadIndex(ctx context.Context, repo restic.Repository, id restic.ID) (*repository.Index, error) { + buf, err := repo.LoadAndDecrypt(ctx, nil, restic.IndexFile, id) + if err != nil { + return nil, err + } + + idx, oldFormat, err := repository.DecodeIndex(buf, id) + if oldFormat { + fmt.Fprintf(os.Stderr, "index %v has old format\n", id.Str()) + } + return idx, err +} + func BenchmarkLoadIndex(b *testing.B) { repository.TestUseLowSecurityKDFParameters(b) @@ -323,7 +339,7 @@ func BenchmarkLoadIndex(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - _, err := repository.LoadIndex(context.TODO(), repo, id) + _, err := loadIndex(context.TODO(), repo, id) rtest.OK(b, err) } } @@ -373,7 +389,7 @@ func TestRepositoryIncrementalIndex(t *testing.T) { packEntries := make(map[restic.ID]map[restic.ID]struct{}) err := repo.List(context.TODO(), restic.IndexFile, func(id restic.ID, size int64) error { - idx, err := repository.LoadIndex(context.TODO(), repo, id) + idx, err := loadIndex(context.TODO(), repo, id) rtest.OK(t, err) for pb := range idx.Each(context.TODO()) {