Added tests for service block parsing

This commit is contained in:
Diptanu Choudhury 2015-11-17 01:51:08 -05:00
parent ead6e09a79
commit 36520a90b3
3 changed files with 29 additions and 1 deletions

View file

@ -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

View file

@ -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",

View file

@ -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