mirror of
https://github.com/octoleo/restic.git
synced 2025-01-05 08:02:22 +00:00
rewrite: Add tests for further ways to use the command
This commit is contained in:
parent
0224e276ec
commit
ec0c91e233
@ -5,23 +5,22 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/restic/restic/internal/restic"
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testRunRewriteExclude(t testing.TB, gopts GlobalOptions, excludes []string) {
|
func testRunRewriteExclude(t testing.TB, gopts GlobalOptions, excludes []string, forget bool) {
|
||||||
opts := RewriteOptions{
|
opts := RewriteOptions{
|
||||||
excludePatternOptions: excludePatternOptions{
|
excludePatternOptions: excludePatternOptions{
|
||||||
Excludes: excludes,
|
Excludes: excludes,
|
||||||
},
|
},
|
||||||
|
Forget: forget,
|
||||||
}
|
}
|
||||||
|
|
||||||
rtest.OK(t, runRewrite(context.TODO(), opts, gopts, nil))
|
rtest.OK(t, runRewrite(context.TODO(), opts, gopts, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRewrite(t *testing.T) {
|
func createBasicRewriteRepo(t testing.TB, env *testEnvironment) restic.ID {
|
||||||
env, cleanup := withTestEnvironment(t)
|
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
testSetupBackupData(t, env)
|
testSetupBackupData(t, env)
|
||||||
|
|
||||||
// create backup
|
// create backup
|
||||||
@ -30,9 +29,45 @@ func TestRewrite(t *testing.T) {
|
|||||||
rtest.Assert(t, len(snapshotIDs) == 1, "expected one snapshot, got %v", snapshotIDs)
|
rtest.Assert(t, len(snapshotIDs) == 1, "expected one snapshot, got %v", snapshotIDs)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
|
|
||||||
|
return snapshotIDs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRewrite(t *testing.T) {
|
||||||
|
env, cleanup := withTestEnvironment(t)
|
||||||
|
defer cleanup()
|
||||||
|
createBasicRewriteRepo(t, env)
|
||||||
|
|
||||||
// exclude some data
|
// exclude some data
|
||||||
testRunRewriteExclude(t, env.gopts, []string{"3"})
|
testRunRewriteExclude(t, env.gopts, []string{"3"}, false)
|
||||||
snapshotIDs = testRunList(t, "snapshots", env.gopts)
|
snapshotIDs := testRunList(t, "snapshots", env.gopts)
|
||||||
rtest.Assert(t, len(snapshotIDs) == 2, "expected two snapshots, got %v", snapshotIDs)
|
rtest.Assert(t, len(snapshotIDs) == 2, "expected two snapshots, got %v", snapshotIDs)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRewriteUnchanged(t *testing.T) {
|
||||||
|
env, cleanup := withTestEnvironment(t)
|
||||||
|
defer cleanup()
|
||||||
|
snapshotID := createBasicRewriteRepo(t, env)
|
||||||
|
|
||||||
|
// use an exclude that will not exclude anything
|
||||||
|
testRunRewriteExclude(t, env.gopts, []string{"3dflkhjgdflhkjetrlkhjgfdlhkj"}, false)
|
||||||
|
newSnapshotIDs := testRunList(t, "snapshots", env.gopts)
|
||||||
|
rtest.Assert(t, len(newSnapshotIDs) == 1, "expected one snapshot, got %v", newSnapshotIDs)
|
||||||
|
rtest.Assert(t, snapshotID == newSnapshotIDs[0], "snapshot id changed unexpectedly")
|
||||||
|
testRunCheck(t, env.gopts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRewriteReplace(t *testing.T) {
|
||||||
|
env, cleanup := withTestEnvironment(t)
|
||||||
|
defer cleanup()
|
||||||
|
snapshotID := createBasicRewriteRepo(t, env)
|
||||||
|
|
||||||
|
// exclude some data
|
||||||
|
testRunRewriteExclude(t, env.gopts, []string{"3"}, true)
|
||||||
|
newSnapshotIDs := testRunList(t, "snapshots", env.gopts)
|
||||||
|
rtest.Assert(t, len(newSnapshotIDs) == 1, "expected one snapshot, got %v", newSnapshotIDs)
|
||||||
|
rtest.Assert(t, snapshotID != newSnapshotIDs[0], "snapshot id should have changed")
|
||||||
|
// check forbids unused blobs, thus remove them first
|
||||||
|
testRunPrune(t, env.gopts, PruneOptions{MaxUnused: "0"})
|
||||||
|
testRunCheck(t, env.gopts)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user