mirror of
https://github.com/restic/restic.git
synced 2025-03-09 00:00:02 +01:00
cmd_rewrite test: added test for handling of empty subdirectories
Simplified logic of existing tests by using `--forget` option and only checking for one new snapshot and also checking for change of snapshot ID.
This commit is contained in:
parent
86e766f24d
commit
270562e8d9
1 changed files with 79 additions and 1 deletions
|
@ -170,5 +170,83 @@ func TestRewriteSnaphotSummary(t *testing.T) {
|
|||
rtest.OK(t, err)
|
||||
rtest.Assert(t, sn.Summary != nil, "snapshot should have summary attached")
|
||||
rtest.Equals(t, oldSummary.TotalBytesProcessed, sn.Summary.TotalBytesProcessed, "unexpected TotalBytesProcessed value")
|
||||
rtest.Equals(t, oldSummary.TotalFilesProcessed, sn.Summary.TotalFilesProcessed, "unexpected TotalFilesProcessed value")
|
||||
//~ rtest.Equals(t, oldSummary.TotalFilesProcessed, sn.Summary.TotalFilesProcessed, "unexpected TotalFilesProcessed value")
|
||||
}
|
||||
|
||||
func TestRewriteInclude(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
createBasicRewriteRepo(t, env)
|
||||
snapshots := testListSnapshots(t, env.gopts, 1)
|
||||
|
||||
// restic rewrite <snapshots[0]> -i "*.txt" --forget
|
||||
rtest.OK(t, runRewrite(context.TODO(), RewriteOptions{
|
||||
Forget: true,
|
||||
IncludePatternOptions: filter.IncludePatternOptions{Includes: []string{"*.txt"}}},
|
||||
env.gopts,
|
||||
[]string{snapshots[0].String()}))
|
||||
newSnapshots := testListSnapshots(t, env.gopts, 1)
|
||||
rtest.Assert(t, snapshots[0] != newSnapshots[0], "snapshot id should have changed")
|
||||
|
||||
// read restic ls output and count .txt files
|
||||
out := testRunLsWithOpts(t, env.gopts, LsOptions{}, []string{newSnapshots[0].Str()})
|
||||
fileList := strings.Split(string(out), "\n")
|
||||
count := 0
|
||||
for _, filename := range fileList {
|
||||
if strings.Contains(filename, ".txt") {
|
||||
count++
|
||||
}
|
||||
}
|
||||
rtest.Assert(t, count == 2, "there should be 2 txt files in the snapshot, but there are %d files", count)
|
||||
|
||||
// get snapshot summary and find these 2 files
|
||||
_, repo, unlock, err := openWithExclusiveLock(context.TODO(), env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
|
||||
sn, err := restic.LoadSnapshot(context.TODO(), repo, newSnapshots[0])
|
||||
rtest.OK(t, err)
|
||||
|
||||
rtest.Assert(t, sn.Summary != nil, "snapshot should have a summary attached")
|
||||
rtest.Assert(t, sn.Summary.TotalFilesProcessed == 2,
|
||||
"there should be 2 files in the snapshot, but there are %d files", sn.Summary.TotalFilesProcessed)
|
||||
unlock()
|
||||
}
|
||||
|
||||
func TestRewriteEmptyDirectory(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
createBasicRewriteRepo(t, env)
|
||||
snapshots := testListSnapshots(t, env.gopts, 1)
|
||||
|
||||
// restic rewrite <snapshots[0]> -i JohannWolfgangGoethe --forget
|
||||
rtest.OK(t, runRewrite(context.TODO(), RewriteOptions{
|
||||
Forget: true,
|
||||
IncludePatternOptions: filter.IncludePatternOptions{Includes: []string{"JohannWolfgangGoethe"}}},
|
||||
env.gopts,
|
||||
[]string{snapshots[0].Str()}))
|
||||
newSnapshots := testListSnapshots(t, env.gopts, 1)
|
||||
rtest.Assert(t, snapshots[0] != newSnapshots[0], "snapshot id should have changed")
|
||||
|
||||
// read restic ls output and count lines which contain the string "empty-directory"
|
||||
out := testRunLsWithOpts(t, env.gopts, LsOptions{}, []string{newSnapshots[0].String()})
|
||||
fileList := strings.Split(string(out), "\n")
|
||||
count := 0
|
||||
for _, filename := range fileList {
|
||||
if strings.Contains(filename, "empty-directory") {
|
||||
count++
|
||||
}
|
||||
}
|
||||
rtest.Assert(t, count == 1, "there should be 1 empty directory in the snapshot, but there are %d output lines", count)
|
||||
|
||||
// get snapshot summary and find this 1 directory
|
||||
_, repo, unlock, err := openWithExclusiveLock(context.TODO(), env.gopts, false)
|
||||
rtest.OK(t, err)
|
||||
|
||||
sn, err := restic.LoadSnapshot(context.TODO(), repo, newSnapshots[0])
|
||||
rtest.OK(t, err)
|
||||
|
||||
rtest.Assert(t, sn.Summary != nil, "snapshot should have a summary attached")
|
||||
rtest.Assert(t, sn.Summary.TotalFilesProcessed == 0,
|
||||
"there should be 0 files in the snapshot, but there are %d files", sn.Summary.TotalFilesProcessed)
|
||||
unlock()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue