Add per-job backup retention
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user