From dc6a832cc30c9a4cc320e3b5ac66c9cc5c97d98f Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 22 Jan 2017 09:59:19 +0100 Subject: [PATCH 1/4] Correct BenchmarkIndexSave --- src/restic/index/index_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/restic/index/index_test.go b/src/restic/index/index_test.go index 27aba6491..030789328 100644 --- a/src/restic/index/index_test.go +++ b/src/restic/index/index_test.go @@ -150,7 +150,7 @@ func BenchmarkIndexSave(b *testing.B) { for i := 0; i < 8000; i++ { entries := make([]restic.Blob, 0, 200) - for j := 0; j < len(entries); j++ { + for j := 0; j < cap(entries); j++ { entries = append(entries, restic.Blob{ ID: restic.NewRandomID(), Length: 1000, From 4f780a01f9912bde9a4353d3a0dde42b0d7b0efb Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 22 Jan 2017 22:09:56 +0100 Subject: [PATCH 2/4] Index: Test pack ID --- src/restic/index/index_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/restic/index/index_test.go b/src/restic/index/index_test.go index 030789328..370625faf 100644 --- a/src/restic/index/index_test.go +++ b/src/restic/index/index_test.go @@ -27,9 +27,14 @@ func createFilledRepo(t testing.TB, snapshots int, dup float32) (restic.Reposito func validateIndex(t testing.TB, repo restic.Repository, idx *Index) { for id := range repo.List(restic.DataFile, nil) { - if _, ok := idx.Packs[id]; !ok { + p, ok := idx.Packs[id] + if !ok { t.Errorf("pack %v missing from index", id.Str()) } + + if !p.ID.Equal(id) { + t.Errorf("pack %v has invalid ID: want %v, got %v", id.Str(), id, p.ID) + } } } From 5e3365d2336a1865cb0b439acaad3e66976aeb8b Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 22 Jan 2017 22:10:36 +0100 Subject: [PATCH 3/4] Index: Store pack ID --- src/restic/index/index.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/restic/index/index.go b/src/restic/index/index.go index 6a122e67a..f1c41b79f 100644 --- a/src/restic/index/index.go +++ b/src/restic/index/index.go @@ -169,7 +169,7 @@ func (idx *Index) AddPack(id restic.ID, size int64, entries []restic.Blob) error return errors.Errorf("pack %v already present in the index", id.Str()) } - idx.Packs[id] = Pack{Size: size, Entries: entries} + idx.Packs[id] = Pack{ID: id, Size: size, Entries: entries} return nil } From af1cc0717bab6a4e63c8f6dcb8c35969dc797a63 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 22 Jan 2017 22:23:30 +0100 Subject: [PATCH 4/4] Add integration test for forget and prune --- src/cmds/restic/integration_test.go | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/cmds/restic/integration_test.go b/src/cmds/restic/integration_test.go index d67842682..a3734bd02 100644 --- a/src/cmds/restic/integration_test.go +++ b/src/cmds/restic/integration_test.go @@ -159,6 +159,15 @@ func testRunFind(t testing.TB, gopts GlobalOptions, pattern string) []string { return strings.Split(string(buf.Bytes()), "\n") } +func testRunForget(t testing.TB, gopts GlobalOptions, args ...string) { + opts := ForgetOptions{} + OK(t, runForget(opts, gopts, args)) +} + +func testRunPrune(t testing.TB, gopts GlobalOptions) { + OK(t, runPrune(gopts)) +} + func TestBackup(t *testing.T) { withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) { datafile := filepath.Join("testdata", "backup-data.tar.gz") @@ -947,3 +956,33 @@ func TestCheckRestoreNoLock(t *testing.T) { testRunRestore(t, gopts, filepath.Join(env.base, "restore"), snapshotIDs[0]) }) } + +func TestPrune(t *testing.T) { + withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) { + datafile := filepath.Join("testdata", "backup-data.tar.gz") + fd, err := os.Open(datafile) + if os.IsNotExist(errors.Cause(err)) { + t.Skipf("unable to find data file %q, skipping", datafile) + return + } + OK(t, err) + OK(t, fd.Close()) + + testRunInit(t, gopts) + + SetupTarTestFixture(t, env.testdata, datafile) + opts := BackupOptions{} + + testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "1")}, opts, gopts) + testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "2")}, opts, gopts) + testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "3")}, opts, gopts) + + snapshotIDs := testRunList(t, "snapshots", gopts) + Assert(t, len(snapshotIDs) == 3, + "expected one snapshot, got %v", snapshotIDs) + + testRunForget(t, gopts, snapshotIDs[0].String()) + testRunPrune(t, gopts) + testRunCheck(t, gopts) + }) +}