Add type-aware backup job forms

This commit is contained in:
Mikei386
2026-06-14 12:46:11 +02:00
parent 92564a1620
commit 800cb60f83
13 changed files with 153 additions and 17 deletions
+7
View File
@@ -74,6 +74,13 @@ func ValidateJob(j Job) error {
return errors.New("source requires path or workloadId")
}
}
if j.Type == JobDocker || j.Type == JobVM {
for _, source := range j.Sources {
if source.WorkloadID == "" {
return errors.New("docker and vm jobs require workload selections")
}
}
}
if j.Compression != "auto" && j.Compression != "off" && j.Compression != "max" {
return errors.New("compression must be auto, off, or max")
}
+11
View File
@@ -34,3 +34,14 @@ func TestRepositoryCannotBeSharedByJobs(t *testing.T) {
t.Fatal("shared repository accepted")
}
}
func TestDockerJobRequiresWorkloadSources(t *testing.T) {
job := Job{SchemaVersion: 1, ID: "docker-job", Name: "Docker", Type: JobDocker, RepositoryID: "repo", Sources: []Source{{Path: "/mnt/user/appdata"}}, Consistency: Consistency{Mode: "live"}, Compression: "auto"}
if err := ValidateJob(job); err == nil {
t.Fatal("docker path source accepted without workload selection")
}
job.Sources = []Source{{WorkloadID: "plex"}}
if err := ValidateJob(job); err != nil {
t.Fatalf("valid docker workload rejected: %v", err)
}
}