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 return nil
} }
var check interface{}
for k, v := range rawMap { for k, v := range rawMap {
if strings.ToLower(k) == "check" { switch strings.ToLower(k) {
check = v case "check":
if err := FixupCheckType(v); err != nil {
return err
}
case "checks":
chkTypes, ok := v.([]interface{})
if !ok {
return nil
}
for _, chkType := range chkTypes {
if err := FixupCheckType(chkType); err != nil {
return err
}
}
} }
} }
if check == nil { return nil
return nil
}
return FixupCheckType(check)
} }
if err := decodeBody(req, &args, decodeCB); err != nil { if err := decodeBody(req, &args, decodeCB); err != nil {
resp.WriteHeader(400) resp.WriteHeader(400)

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

Loading…
Cancel
Save