rewrite - have more tests

This commit is contained in:
Winfried Plappert 2025-02-20 13:20:16 +00:00
parent ec34ffe31f
commit 79cc72183e
2 changed files with 33 additions and 3 deletions

View File

@ -219,10 +219,10 @@ func TestRewriteEmptyDirectory(t *testing.T) {
createBasicRewriteRepo(t, env) createBasicRewriteRepo(t, env)
snapshots := testListSnapshots(t, env.gopts, 1) snapshots := testListSnapshots(t, env.gopts, 1)
// restic rewrite <snapshots[0]> -i JohannWolfgangGoethe --forget // restic rewrite <snapshots[0]> -i empty-directory --forget
rtest.OK(t, runRewrite(context.TODO(), RewriteOptions{ rtest.OK(t, runRewrite(context.TODO(), RewriteOptions{
Forget: true, Forget: true,
IncludePatternOptions: filter.IncludePatternOptions{Includes: []string{"JohannWolfgangGoethe"}}}, IncludePatternOptions: filter.IncludePatternOptions{Includes: []string{"empty-directory"}}},
env.gopts, env.gopts,
[]string{snapshots[0].Str()})) []string{snapshots[0].Str()}))
newSnapshots := testListSnapshots(t, env.gopts, 1) newSnapshots := testListSnapshots(t, env.gopts, 1)
@ -272,3 +272,33 @@ func TestRewriteConflictingOptions(t *testing.T) {
}, env.gopts, []string{"latest"}) }, env.gopts, []string{"latest"})
rtest.Assert(t, err != nil, "You cannot specify include or exclude options together with --snapshot-summary!") rtest.Assert(t, err != nil, "You cannot specify include or exclude options together with --snapshot-summary!")
} }
func TestRewriteIncludeNothing(t *testing.T) {
env, cleanup := withTestEnvironment(t)
defer cleanup()
createBasicRewriteRepo(t, env)
testListSnapshots(t, env.gopts, 1)
// restic rewrite latest -i nothing-whatsoever --forget
rtest.OK(t, runRewrite(context.TODO(), RewriteOptions{
Forget: true,
IncludePatternOptions: filter.IncludePatternOptions{Includes: []string{"nothing-whatsoever"}}},
env.gopts,
[]string{"latest"}))
testListSnapshots(t, env.gopts, 1)
}
func TestRewriteExcludeNothing(t *testing.T) {
env, cleanup := withTestEnvironment(t)
defer cleanup()
createBasicRewriteRepo(t, env)
testListSnapshots(t, env.gopts, 1)
// restic rewrite latest -e nothing-whatsoever --forget
rtest.OK(t, runRewrite(context.TODO(), RewriteOptions{
Forget: true,
ExcludePatternOptions: filter.ExcludePatternOptions{Excludes: []string{"nothing-whatsoever"}}},
env.gopts,
[]string{"latest"}))
testListSnapshots(t, env.gopts, 1)
}

View File

@ -334,7 +334,7 @@ func TestSnapshotSizeQuery(t *testing.T) {
} }
return node return node
} }
rewriter, querySize := NewSnapshotSizeRewriter(rewriteNode, false) rewriter, querySize := NewSnapshotSizeRewriter(rewriteNode, func(_ string) bool { return true })
newRoot, err := rewriter.RewriteTree(ctx, modrepo, "/", root) newRoot, err := rewriter.RewriteTree(ctx, modrepo, "/", root)
if err != nil { if err != nil {
t.Error(err) t.Error(err)