parent
e98e599419
commit
517c799439
|
@ -1587,8 +1587,12 @@ func (j *Job) Validate() error {
|
|||
if j.Name == "" {
|
||||
mErr.Errors = append(mErr.Errors, errors.New("Missing job name"))
|
||||
}
|
||||
if j.Type == "" {
|
||||
switch j.Type {
|
||||
case JobTypeCore, JobTypeService, JobTypeBatch, JobTypeSystem:
|
||||
case "":
|
||||
mErr.Errors = append(mErr.Errors, errors.New("Missing job type"))
|
||||
default:
|
||||
mErr.Errors = append(mErr.Errors, fmt.Errorf("Invalid job type: %q", j.Type))
|
||||
}
|
||||
if j.Priority < JobMinPriority || j.Priority > JobMaxPriority {
|
||||
mErr.Errors = append(mErr.Errors, fmt.Errorf("Job priority must be between [%d, %d]", JobMinPriority, JobMaxPriority))
|
||||
|
|
|
@ -38,6 +38,14 @@ func TestJob_Validate(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
j = &Job{
|
||||
Type: "invalid-job-type",
|
||||
}
|
||||
err = j.Validate()
|
||||
if expected := `Invalid job type: "invalid-job-type"`; !strings.Contains(err.Error(), expected) {
|
||||
t.Errorf("expected %s but found: %v", expected, err)
|
||||
}
|
||||
|
||||
j = &Job{
|
||||
Type: JobTypeService,
|
||||
Periodic: &PeriodicConfig{
|
||||
|
|
Loading…
Reference in a new issue