Reject backup jobs without paths
CI / Test (store) (pull_request) Successful in 5s
CI / Lint (pull_request) Successful in 12s
CI / Test (rest) (pull_request) Successful in 20s
CI / Build (windows/amd64) (pull_request) Successful in 8s
CI / Build (linux/amd64) (pull_request) Successful in 8s
CI / Build (linux/arm64) (pull_request) Successful in 7s
CI / Test (server-http) (pull_request) Successful in 1m36s
e2e / Playwright vs docker-compose (pull_request) Successful in 1m26s

This commit is contained in:
2026-08-22 13:42:42 +01:00
parent 25866ff102
commit 4f56b8f705
3 changed files with 38 additions and 5 deletions
+28
View File
@@ -14,6 +14,34 @@ import (
"gitea.dcglab.co.uk/steve/restic-manager/internal/store"
)
func TestRunNowBackupRejectsEmptyPaths(t *testing.T) {
t.Parallel()
_, ts, st := rawTestServer(t)
cookie := loginAsAdmin(t, st)
hostID := makeHost(t, st, "empty-backup-host")
req, _ := stdhttp.NewRequest(stdhttp.MethodPost, ts.URL+"/api/hosts/"+hostID+"/jobs",
bytes.NewReader([]byte(`{"kind":"backup"}`)))
req.Header.Set("Content-Type", "application/json")
req.AddCookie(cookie)
res, err := stdhttp.DefaultClient.Do(req)
if err != nil {
t.Fatalf("post run-now: %v", err)
}
defer res.Body.Close()
if res.StatusCode != stdhttp.StatusUnprocessableEntity {
t.Fatalf("status: got %d, want 422", res.StatusCode)
}
body := readJSONError(t, res.Body)
if body.Code != "backup_paths_required" {
t.Fatalf("code: got %q", body.Code)
}
var jobs int
_ = st.DB().QueryRow(`SELECT COUNT(*) FROM jobs WHERE host_id = ?`, hostID).Scan(&jobs)
if jobs != 0 {
t.Fatalf("invalid backup created %d jobs", jobs)
}
}
func TestRunNowForgetShipsRetentionGroupsAndDryRun(t *testing.T) {
t.Parallel()
srv, ts, st := rawTestServer(t)