diff --git a/cmd/restic/cmd_recover_integration_test.go b/cmd/restic/cmd_recover_integration_test.go new file mode 100644 index 000000000..c3d210200 --- /dev/null +++ b/cmd/restic/cmd_recover_integration_test.go @@ -0,0 +1,37 @@ +package main + +import ( + "context" + "testing" + + rtest "github.com/restic/restic/internal/test" + "github.com/restic/restic/internal/ui/termstatus" +) + +func testRunRecover(t testing.TB, gopts GlobalOptions) { + rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return runRecover(context.TODO(), gopts, term) + })) +} + +func TestRecover(t *testing.T) { + env, cleanup := withTestEnvironment(t) + // must list index more than once + env.gopts.backendTestHook = nil + defer cleanup() + + testSetupBackupData(t, env) + + // create backup and forget it afterwards + testRunBackup(t, "", []string{env.testdata}, BackupOptions{}, env.gopts) + ids := testListSnapshots(t, env.gopts, 1) + sn := testLoadSnapshot(t, env.gopts, ids[0]) + testRunForget(t, env.gopts, ForgetOptions{}, ids[0].String()) + testListSnapshots(t, env.gopts, 0) + + testRunRecover(t, env.gopts) + ids = testListSnapshots(t, env.gopts, 1) + testRunCheck(t, env.gopts) + // check that the root tree is included in the snapshot + rtest.OK(t, runCat(context.TODO(), env.gopts, []string{"tree", ids[0].String() + ":" + sn.Tree.Str()})) +} diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 21944a9ce..dff84522a 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -354,6 +354,15 @@ func lastSnapshot(old, new map[string]struct{}) (map[string]struct{}, string) { return old, "" } +func testLoadSnapshot(t testing.TB, gopts GlobalOptions, id restic.ID) *restic.Snapshot { + _, repo, unlock, err := openWithReadLock(context.TODO(), gopts, false) + defer unlock() + rtest.OK(t, err) + snapshot, err := restic.LoadSnapshot(context.TODO(), repo, id) + rtest.OK(t, err) + return snapshot +} + func appendRandomData(filename string, bytes uint) error { f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0666) if err != nil {