From 575ed9a47e5179ca00448407924a05ebb4c97800 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 31 Mar 2020 17:34:46 +0200 Subject: [PATCH] Test that rebuild-index errors when old index cannot be removed --- cmd/restic/integration_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index f3e02a37b..1333bd3aa 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -1132,6 +1132,37 @@ func TestRebuildIndexAlwaysFull(t *testing.T) { TestRebuildIndex(t) } +type appendOnlyBackend struct { + restic.Backend +} + +// called via repo.Backend().Remove() +func (b *appendOnlyBackend) Remove(ctx context.Context, h restic.Handle) error { + return errors.Errorf("Failed to remove %v", h) +} + +func TestRebuildIndexFailsOnAppendOnly(t *testing.T) { + env, cleanup := withTestEnvironment(t) + defer cleanup() + + datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz") + rtest.SetupTarTestFixture(t, env.base, datafile) + + globalOptions.stdout = ioutil.Discard + defer func() { + globalOptions.stdout = os.Stdout + }() + + env.gopts.backendTestHook = func(r restic.Backend) (restic.Backend, error) { + return &appendOnlyBackend{r}, nil + } + err := runRebuildIndex(env.gopts) + if err == nil { + t.Error("expected rebuildIndex to fail") + } + t.Log(err) +} + func TestCheckRestoreNoLock(t *testing.T) { env, cleanup := withTestEnvironment(t) defer cleanup()