1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-03-30 00:00:14 +01:00

recover: add minimal integration test

This commit is contained in:
Michael Eischer 2025-03-23 17:59:14 +01:00
parent 2409078d55
commit 99fdb00d39
2 changed files with 46 additions and 0 deletions

View file

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

View file

@ -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 {