Add test for optimize command with old indexes

This commit is contained in:
Alexander Neumann 2015-11-08 22:21:08 +01:00
parent c59b12c939
commit 2e6eee991d
1 changed files with 31 additions and 12 deletions

View File

@ -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)
}
})
}
}