diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 5c5a196d1..2fafee92f 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -699,16 +699,35 @@ func TestRebuildIndexAlwaysFull(t *testing.T) { TestRebuildIndex(t) } -func TestOptimizeRemoveUnusedBlobs(t *testing.T) { - withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { - datafile := filepath.Join("..", "..", "checker", "testdata", "checker-test-repo.tar.gz") - SetupTarTestFixture(t, env.base, datafile) - - // snapshotIDs := cmdList(t, global, "snapshots") - // t.Logf("snapshots: %v", snapshotIDs) - - OK(t, os.Remove(filepath.Join(env.repo, "snapshots", "a13c11e582b77a693dd75ab4e3a3ba96538a056594a4b9076e4cacebe6e06d43"))) - cmdOptimize(t, global) - cmdCheck(t, global) - }) +var optimizeTests = []struct { + testFilename string + snapshotID string +}{ + { + filepath.Join("..", "..", "checker", "testdata", "checker-test-repo.tar.gz"), + "a13c11e582b77a693dd75ab4e3a3ba96538a056594a4b9076e4cacebe6e06d43", + }, + { + filepath.Join("..", "..", "repository", "testdata", "old-index-repo.tar.gz"), + "", + }, +} + +func TestOptimizeRemoveUnusedBlobs(t *testing.T) { + for i, test := range optimizeTests { + withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { + SetupTarTestFixture(t, env.base, test.testFilename) + + if test.snapshotID != "" { + OK(t, os.Remove(filepath.Join(env.repo, "snapshots", test.snapshotID))) + } + + cmdOptimize(t, global) + output := cmdCheckOutput(t, global) + + if len(output) > 0 { + t.Errorf("expected no output for check in test %d, got:\n%v", i, output) + } + }) + } }