agent: support adding multiple checks during service registration from the API

pull/591/head
Ryan Uber 10 years ago
parent 674be58e55
commit 2a7211cd5d

@ -132,17 +132,25 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re
return nil
}
var check interface{}
for k, v := range rawMap {
if strings.ToLower(k) == "check" {
check = v
switch strings.ToLower(k) {
case "check":
if err := FixupCheckType(v); err != nil {
return err
}
}
if check == nil {
case "checks":
chkTypes, ok := v.([]interface{})
if !ok {
return nil
}
return FixupCheckType(check)
for _, chkType := range chkTypes {
if err := FixupCheckType(chkType); err != nil {
return err
}
}
}
}
return nil
}
if err := decodeBody(req, &args, decodeCB); err != nil {
resp.WriteHeader(400)

@ -430,6 +430,14 @@ func TestHTTPAgentRegisterService(t *testing.T) {
Check: CheckType{
TTL: 15 * time.Second,
},
Checks: CheckTypes{
&CheckType{
TTL: 20 * time.Second,
},
&CheckType{
TTL: 30 * time.Second,
},
},
}
req.Body = encodeReq(args)
@ -447,12 +455,13 @@ func TestHTTPAgentRegisterService(t *testing.T) {
}
// Ensure we have a check mapping
if _, ok := srv.agent.state.Checks()["service:test"]; !ok {
t.Fatalf("missing test check")
checks := srv.agent.state.Checks()
if len(checks) != 3 {
t.Fatalf("bad: %v", checks)
}
if _, ok := srv.agent.checkTTLs["service:test"]; !ok {
t.Fatalf("missing test check ttl")
if len(srv.agent.checkTTLs) != 3 {
t.Fatalf("missing test check ttls: %v", srv.agent.checkTTLs)
}
}

Loading…
Cancel
Save