diff --git a/jobspec/parse.go b/jobspec/parse.go index 6584f3eb3..37e96b0b0 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -77,7 +77,8 @@ func parseJob(result *structs.Job, obj *hclobj.Object) error { delete(m, "constraint") delete(m, "meta") - // Set the name to the object key + // Set the ID and name to the object key + result.ID = obj.Key result.Name = obj.Key // Defaults diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 793197c79..93eca1330 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -17,6 +17,7 @@ func TestParse(t *testing.T) { { "basic.hcl", &structs.Job{ + ID: "binstore-storagelocker", Name: "binstore-storagelocker", Type: "service", Priority: 50, @@ -128,6 +129,7 @@ func TestParse(t *testing.T) { { "default-job.hcl", &structs.Job{ + ID: "foo", Name: "foo", Priority: 50, Region: "global", @@ -135,6 +137,18 @@ func TestParse(t *testing.T) { }, false, }, + + { + "specify-job.hcl", + &structs.Job{ + ID: "job1", + Name: "My Job", + Priority: 50, + Region: "global", + Type: "service", + }, + false, + }, } for _, tc := range cases { diff --git a/jobspec/test-fixtures/specify-job.hcl b/jobspec/test-fixtures/specify-job.hcl new file mode 100644 index 000000000..24d70b60f --- /dev/null +++ b/jobspec/test-fixtures/specify-job.hcl @@ -0,0 +1,4 @@ +job "default" { + id = "job1" + name = "My Job" +}