From b0446491184d439dda805e6795ce0b8215c98e10 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 9 Sep 2022 23:33:18 +0200 Subject: [PATCH] rewrite: add minimal test --- cmd/restic/integration_rewrite_test.go | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cmd/restic/integration_rewrite_test.go diff --git a/cmd/restic/integration_rewrite_test.go b/cmd/restic/integration_rewrite_test.go new file mode 100644 index 000000000..b0f6b02ac --- /dev/null +++ b/cmd/restic/integration_rewrite_test.go @@ -0,0 +1,38 @@ +package main + +import ( + "context" + "path/filepath" + "testing" + + rtest "github.com/restic/restic/internal/test" +) + +func testRunRewriteExclude(t testing.TB, gopts GlobalOptions, excludes []string) { + opts := RewriteOptions{ + excludePatternOptions: excludePatternOptions{ + Excludes: excludes, + }, + } + + rtest.OK(t, runRewrite(context.TODO(), opts, gopts, nil)) +} + +func TestRewrite(t *testing.T) { + env, cleanup := withTestEnvironment(t) + defer cleanup() + + testSetupBackupData(t, env) + + // create backup + testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata"}, BackupOptions{}, env.gopts) + snapshotIDs := testRunList(t, "snapshots", env.gopts) + rtest.Assert(t, len(snapshotIDs) == 1, "expected one snapshot, got %v", snapshotIDs) + testRunCheck(t, env.gopts) + + // exclude some data + testRunRewriteExclude(t, env.gopts, []string{"3"}) + snapshotIDs = testRunList(t, "snapshots", env.gopts) + rtest.Assert(t, len(snapshotIDs) == 2, "expected two snapshots, got %v", snapshotIDs) + testRunCheck(t, env.gopts) +}