From b46ef51404dfc5d55938427eb430146cdea16a0f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 14 Sep 2015 18:34:26 -0700 Subject: [PATCH] jobspec: defaults --- jobspec/parse.go | 5 +++++ jobspec/parse_test.go | 11 +++++++++++ jobspec/test-fixtures/default-job.hcl | 1 + 3 files changed, 17 insertions(+) create mode 100644 jobspec/test-fixtures/default-job.hcl diff --git a/jobspec/parse.go b/jobspec/parse.go index 3a1929d13..6584f3eb3 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -80,6 +80,11 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error { // Set the name to the object key result.Name = obj.Key + // Defaults + result.Priority = 50 + result.Region = "global" + result.Type = "service" + // Decode the rest if err := mapstructure.WeakDecode(m, result); err != nil { return err diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 49d4f98f3..793197c79 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -124,6 +124,17 @@ func TestParse(t *testing.T) { nil, true, }, + + { + "default-job.hcl", + &structs.Job{ + Name: "foo", + Priority: 50, + Region: "global", + Type: "service", + }, + false, + }, } for _, tc := range cases { diff --git a/jobspec/test-fixtures/default-job.hcl b/jobspec/test-fixtures/default-job.hcl new file mode 100644 index 000000000..314138973 --- /dev/null +++ b/jobspec/test-fixtures/default-job.hcl @@ -0,0 +1 @@ +job "foo" {}