diff --git a/jobspec/parse.go b/jobspec/parse.go index de7d9314c..e1932cfaa 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -436,7 +436,7 @@ func parseTasks(result *[]*structs.Task, list *ast.ObjectList) error { service.Checks = make([]structs.ServiceCheck, len(co.Items)) for idx, co := range co.Items { var check structs.ServiceCheck - label := o.Keys[0].Token.Value().(string) + label := co.Keys[0].Token.Value().(string) var cm map[string]interface{} if err := hcl.DecodeObject(&cm, co.Val); err != nil { return err diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 125127de5..1c993caa2 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -94,6 +94,23 @@ func TestParse(t *testing.T) { Config: map[string]interface{}{ "image": "hashicorp/binstore", }, + Services: []structs.Service{ + { + Id: "service-id", + Name: "service-name", + Tags: []string{"foo", "bar"}, + PortLabel: "http", + Checks: []structs.ServiceCheck{ + { + Id: "check-id", + Name: "check-name", + Type: "tcp", + Interval: 10 * time.Second, + Timeout: 2 * time.Second, + }, + }, + }, + }, Env: map[string]string{ "HELLO": "world", "LOREM": "ipsum", diff --git a/jobspec/test-fixtures/basic.hcl b/jobspec/test-fixtures/basic.hcl index 236f4829a..609c8f2f5 100644 --- a/jobspec/test-fixtures/basic.hcl +++ b/jobspec/test-fixtures/basic.hcl @@ -45,6 +45,17 @@ job "binstore-storagelocker" { HELLO = "world" LOREM = "ipsum" } + service "service-id" { + name = "service-name" + tags = ["foo", "bar"] + port = "http" + check "check-id" { + name = "check-name" + type = "tcp" + interval = "10s" + timeout = "2s" + } + } resources { cpu = 500 memory = 128