diff --git a/repository/repository_test.go b/repository/repository_test.go index 1874cfd91..16d3b7175 100644 --- a/repository/repository_test.go +++ b/repository/repository_test.go @@ -6,11 +6,13 @@ import ( "crypto/sha256" "encoding/json" "io" + "path/filepath" "testing" "github.com/restic/restic" "github.com/restic/restic/backend" "github.com/restic/restic/pack" + "github.com/restic/restic/repository" . "github.com/restic/restic/test" ) @@ -194,3 +196,24 @@ func TestLoadJSONUnpacked(t *testing.T) { Equals(t, sn.Hostname, sn2.Hostname) Equals(t, sn.Username, sn2.Username) } + +var repoFixture = filepath.Join("testdata", "test-repo.tar.gz") + +func TestLoadIndex(t *testing.T) { + WithTestEnvironment(t, repoFixture, func(repodir string) { + repo := OpenLocalRepo(t, repodir) + OK(t, repo.LoadIndex()) + }) +} + +func BenchmarkLoadIndex(b *testing.B) { + WithTestEnvironment(b, repoFixture, func(repodir string) { + repo := OpenLocalRepo(b, repodir) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + repo.SetIndex(repository.NewIndex()) + OK(b, repo.LoadIndex()) + } + }) +} diff --git a/repository/testdata/test-repo.tar.gz b/repository/testdata/test-repo.tar.gz new file mode 100644 index 000000000..9cfc38573 Binary files /dev/null and b/repository/testdata/test-repo.tar.gz differ