2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 11:46:36 +00:00

Add TestResetRepository and BenchmarkCreateSnapshot

This commit is contained in:
Alexander Neumann 2016-08-06 17:29:08 +02:00
parent e9cddc0be5
commit fd6c854a21
2 changed files with 29 additions and 0 deletions

View File

@ -184,3 +184,20 @@ func TestCreateSnapshot(t testing.TB, repo *repository.Repository, at time.Time,
return snapshot
}
// TestResetRepository removes all packs and indexes from the repository.
func TestResetRepository(t testing.TB, repo *repository.Repository) {
done := make(chan struct{})
defer close(done)
for _, tpe := range []backend.Type{backend.Snapshot, backend.Index, backend.Data} {
for id := range repo.Backend().List(tpe, done) {
err := repo.Backend().Remove(tpe, id)
if err != nil {
t.Errorf("removing %v (%v) failed: %v", id[0:12], tpe, err)
}
}
}
repo.SetIndex(repository.NewMasterIndex())
}

View File

@ -47,3 +47,15 @@ func TestCreateSnapshot(t *testing.T) {
checker.TestCheckRepo(t, repo)
}
func BenchmarkCreateSnapshot(b *testing.B) {
repo, cleanup := repository.TestRepository(b)
defer cleanup()
b.ResetTimer()
for i := 0; i < b.N; i++ {
restic.TestCreateSnapshot(b, repo, testSnapshotTime, testDepth)
restic.TestResetRepository(b, repo)
}
}