Show restore progress details

This commit is contained in:
Mikei386
2026-06-21 22:59:56 +02:00
parent c014a5f502
commit 41ac4ba43e
10 changed files with 84 additions and 15 deletions
+26
View File
@@ -164,6 +164,32 @@ func TestBackupImageStreamsRawDeviceWithStableFilename(t *testing.T) {
}
}
func TestRestoreReportsProgress(t *testing.T) {
dir := t.TempDir()
argsPath := filepath.Join(dir, "args")
script := filepath.Join(dir, "restic")
body := fmt.Sprintf("#!/bin/sh\nprintf '%%s\\n' \"$@\" > '%s'\nprintf '%%s\\n' '{\"message_type\":\"status\",\"percent_done\":0.25,\"total_files\":8,\"files_done\":2,\"total_bytes\":4096,\"bytes_done\":1024,\"seconds_remaining\":30,\"current_files\":[\"/restore/file.txt\"]}'\n", 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"}
task := model.RestoreTask{SnapshotID: "snap123", Target: "/target", Includes: []string{"/source/file.txt"}}
var progress Progress
if err := runner.Restore(context.Background(), repo, task, func(value Progress) { progress = value }); err != nil {
t.Fatal(err)
}
if progress.PercentDone != 0.25 || progress.FilesDone != 2 || progress.BytesDone != 1024 || progress.SecondsRemaining != 30 || len(progress.CurrentFiles) != 1 {
t.Fatalf("unexpected progress: %+v", progress)
}
args, _ := os.ReadFile(argsPath)
for _, expected := range []string{"restore", "snap123", "--target", "/target", "--json", "--include", "/source/file.txt"} {
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")