From 8dd7fe82ff7b1e35f0619dc0c36b0553f5641047 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 20 Jan 2017 14:46:14 +0100 Subject: [PATCH] Add TestIndexSave --- src/restic/index/index_test.go | 38 +++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/restic/index/index_test.go b/src/restic/index/index_test.go index 8b86b7d53..27aba6491 100644 --- a/src/restic/index/index_test.go +++ b/src/restic/index/index_test.go @@ -3,6 +3,7 @@ package index import ( "math/rand" "restic" + "restic/checker" "restic/repository" "restic/test" "testing" @@ -204,7 +205,7 @@ func loadIndex(t testing.TB, repo restic.Repository) *Index { return idx } -func TestIndexSave(t *testing.T) { +func TestSave(t *testing.T) { repo, cleanup := createFilledRepo(t, 3, 0) defer cleanup() @@ -254,6 +255,41 @@ func TestIndexSave(t *testing.T) { } } +func TestIndexSave(t *testing.T) { + repo, cleanup := createFilledRepo(t, 3, 0) + defer cleanup() + + idx := loadIndex(t, repo) + + id, err := idx.Save(repo, idx.IndexIDs.List()) + if err != nil { + t.Fatalf("unable to save new index: %v", err) + } + + t.Logf("new index saved as %v", id.Str()) + + for id := range idx.IndexIDs { + t.Logf("remove index %v", id.Str()) + err = repo.Backend().Remove(restic.IndexFile, id.String()) + if err != nil { + t.Errorf("error removing index %v: %v", id, err) + } + } + + idx2 := loadIndex(t, repo) + t.Logf("load new index with %d packs", len(idx2.Packs)) + + checker := checker.New(repo) + hints, errs := checker.LoadIndex() + for _, h := range hints { + t.Logf("hint: %v\n", h) + } + + for _, err := range errs { + t.Errorf("checker found error: %v", err) + } +} + func TestIndexAddRemovePack(t *testing.T) { repo, cleanup := createFilledRepo(t, 3, 0) defer cleanup()