Skip to content

Commit

Permalink
Require batch
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Dec 16, 2016
1 parent d1ecd38 commit c308ef7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,11 @@ func (j *Job) Validate() error {
}

if j.IsConstructor() {
if j.Type != JobTypeBatch {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("Constructor job can only be used with %q scheduler", JobTypeBatch))
}

if err := j.Constructor.Validate(); err != nil {
mErr.Errors = append(mErr.Errors, err)
}
Expand Down
16 changes: 14 additions & 2 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ func TestVault_Validate(t *testing.T) {
}
}

func TestDispatchConfig_Validate(t *testing.T) {
func TestConstructorConfig_Validate(t *testing.T) {
d := &ConstructorConfig{
Payload: "foo",
}
Expand All @@ -1463,7 +1463,19 @@ func TestDispatchConfig_Validate(t *testing.T) {
}
}

func TestDispatchConfig_Canonicalize(t *testing.T) {
func TestConstructorConfig_Validate_NonBatch(t *testing.T) {
job := testJob()
job.Constructor = &ConstructorConfig{
Payload: DispatchPayloadOptional,
}
job.Type = JobTypeSystem

if err := job.Validate(); err == nil || !strings.Contains(err.Error(), "only be used with") {
t.Fatalf("Expected bad scheduler tpye: %v", err)
}
}

func TestConstructorConfig_Canonicalize(t *testing.T) {
d := &ConstructorConfig{}
d.Canonicalize()
if d.Payload != DispatchPayloadOptional {
Expand Down

0 comments on commit c308ef7

Please sign in to comment.