Add per-job backup retention

This commit is contained in:
Mikei386
2026-06-14 13:27:25 +02:00
parent 7e2c604c5f
commit 4f76d86b9e
13 changed files with 83 additions and 14 deletions
+25
View File
@@ -45,3 +45,28 @@ func TestBackupUsesPasswordFileAndStructuredArguments(t *testing.T) {
t.Fatal("password file was not provided")
}
}
func TestForgetUsesAgeAndCalendarRetention(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'\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"}
job := model.Job{ID: "job", Retention: model.Retention{KeepWithinDays: 30, Weekly: 4, Monthly: 12}}
if err := runner.Forget(context.Background(), repo, job); err != nil {
t.Fatal(err)
}
args, _ := os.ReadFile(argsPath)
for _, expected := range []string{"--keep-within", "30d", "--keep-weekly", "4", "--keep-monthly", "12"} {
if !strings.Contains(string(args), expected) {
t.Fatalf("retention arguments missing %q: %s", expected, args)
}
}
if strings.Contains(string(args), "--keep-daily") {
t.Fatalf("disabled daily retention was included: %s", args)
}
}