mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 02:45:42 +03:00
Merge pull request #2805 from hashicorp/b-2722-invalid-type
Validate job type
This commit is contained in:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user