Stream snapshot file listings

This commit is contained in:
Mikei386
2026-07-10 12:41:48 +02:00
parent c2f0f0b277
commit f22c2e462d
10 changed files with 59 additions and 19 deletions
+30
View File
@@ -233,6 +233,36 @@ printf '%%s\n' 'Files: 1 new, 1 removed, 2 changed'
}
}
func TestListStreamsSnapshotNodes(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' '{"struct_type":"snapshot","id":"snap"}'
printf '%%s\n' '{"struct_type":"node","path":"/mnt/user","type":"dir"}'
printf '%%s\n' '{"struct_type":"node","path":"/mnt/user/file.txt","type":"file","size":12}'
`, 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"}
items, err := runner.List(context.Background(), repo, "snap", "/mnt/user")
if err != nil {
t.Fatal(err)
}
if len(items) != 2 || items[0]["path"] != "/mnt/user" || items[1]["path"] != "/mnt/user/file.txt" {
t.Fatalf("unexpected items: %+v", items)
}
args, _ := os.ReadFile(argsPath)
for _, expected := range []string{"ls", "snap", "--json", "/mnt/user"} {
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")