Log changed files after backup

This commit is contained in:
Mikei386
2026-07-10 11:32:48 +02:00
parent 99e2753c10
commit 5aa28cf43e
9 changed files with 193 additions and 8 deletions
+43
View File
@@ -190,6 +190,49 @@ func TestRestoreReportsProgress(t *testing.T) {
}
}
func TestDiffReportsLastChangedPaths(t *testing.T) {
dir := t.TempDir()
argsPath := filepath.Join(dir, "args")
script := filepath.Join(dir, "restic")
body := fmt.Sprintf(`#!/bin/sh
printf '%%s\n' "$@" > '%s'
printf '%%s\n' 'comparing snapshot before to after:'
printf '%%s\n' '+ /mnt/user/new.txt'
printf '%%s\n' 'M /mnt/user/modified-a.txt'
printf '%%s\n' '- /mnt/user/removed.txt'
printf '%%s\n' 'M /mnt/user/modified-b.txt'
printf '%%s\n' 'Files: 1 new, 1 removed, 2 changed'
`, argsPath)
if err := os.WriteFile(script, []byte(body), 0700); err != nil {
t.Fatal(err)
}
runner := &Runner{Binary: script, RuntimeDir: dir, Secrets: fakeSecrets{"password": "secret"}}
repo := model.Repository{Type: model.RepositoryLocal, Location: "/repo", PasswordRef: "password"}
diff, err := runner.Diff(context.Background(), repo, "before", "after", 3)
if err != nil {
t.Fatal(err)
}
if diff.Total != 4 || len(diff.Entries) != 3 {
t.Fatalf("unexpected diff result: %+v", diff)
}
expected := []DiffEntry{
{Kind: "modified", Path: "/mnt/user/modified-a.txt"},
{Kind: "removed", Path: "/mnt/user/removed.txt"},
{Kind: "modified", Path: "/mnt/user/modified-b.txt"},
}
for index, entry := range expected {
if diff.Entries[index] != entry {
t.Fatalf("entry %d = %+v, want %+v", index, diff.Entries[index], entry)
}
}
args, _ := os.ReadFile(argsPath)
for _, expected := range []string{"diff", "--metadata", "before", "after"} {
if !strings.Contains(string(args), expected) {
t.Fatalf("arguments missing %q: %s", expected, args)
}
}
}
func TestStatsUsesRequestedRepositoryCountingMode(t *testing.T) {
dir := t.TempDir()
argsPath := filepath.Join(dir, "args")