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