diff --git a/command/run.go b/command/run.go index 5b674b81b..d25692135 100644 --- a/command/run.go +++ b/command/run.go @@ -80,6 +80,9 @@ func (c *RunCommand) Run(args []string) int { return 1 } + // Initialize any fields that need to be. + job.InitFields() + // Check that the job is valid if err := job.Validate(); err != nil { c.Ui.Error(fmt.Sprintf("Error validating job: %s", err)) diff --git a/command/run_test.go b/command/run_test.go index c797ef406..a61f598f2 100644 --- a/command/run_test.go +++ b/command/run_test.go @@ -77,6 +77,7 @@ func TestRunCommand_Fails(t *testing.T) { defer os.Remove(fh3.Name()) _, err = fh3.WriteString(` job "job1" { + type = "service" datacenters = [ "dc1" ] group "group1" { count = 1 diff --git a/command/validate.go b/command/validate.go index 10d03eaca..56bb166d4 100644 --- a/command/validate.go +++ b/command/validate.go @@ -48,6 +48,9 @@ func (c *ValidateCommand) Run(args []string) int { return 1 } + // Initialize any fields that need to be. + job.InitFields() + // Check that the job is valid if err := job.Validate(); err != nil { c.Ui.Error(fmt.Sprintf("Error validating job: %s", err)) diff --git a/command/validate_test.go b/command/validate_test.go index 7e61c19b6..606f75a4a 100644 --- a/command/validate_test.go +++ b/command/validate_test.go @@ -24,6 +24,7 @@ func TestValidateCommand(t *testing.T) { defer os.Remove(fh.Name()) _, err = fh.WriteString(` job "job1" { + type = "service" datacenters = [ "dc1" ] group "group1" { count = 1 diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 981697d8b..2b74c3f1a 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -115,9 +115,11 @@ func TestJob_IsPeriodic(t *testing.T) { func TestTaskGroup_Validate(t *testing.T) { tg := &TaskGroup{ RestartPolicy: &RestartPolicy{ - Interval: 5 * time.Minute, - Delay: 10 * time.Second, - Attempts: 10, + Interval: 5 * time.Minute, + Delay: 10 * time.Second, + Attempts: 10, + RestartOnSuccess: true, + Mode: RestartPolicyModeDelay, }, } err := tg.Validate() @@ -141,9 +143,11 @@ func TestTaskGroup_Validate(t *testing.T) { &Task{}, }, RestartPolicy: &RestartPolicy{ - Interval: 5 * time.Minute, - Delay: 10 * time.Second, - Attempts: 10, + Interval: 5 * time.Minute, + Delay: 10 * time.Second, + Attempts: 10, + RestartOnSuccess: true, + Mode: RestartPolicyModeDelay, }, } err = tg.Validate()