Merge pull request #627 from sttts/api-agent-service-address

Add agent service Address field to the api
This commit is contained in:
Armon Dadgar 2015-01-22 10:00:18 -08:00
commit 9600174ab7
2 changed files with 57 additions and 9 deletions

View File

@ -22,6 +22,7 @@ type AgentService struct {
Service string Service string
Tags []string Tags []string
Port int Port int
Address string
} }
// AgentMember represents a cluster member known to the agent // AgentMember represents a cluster member known to the agent
@ -41,12 +42,13 @@ type AgentMember struct {
// AgentServiceRegistration is used to register a new service // AgentServiceRegistration is used to register a new service
type AgentServiceRegistration struct { type AgentServiceRegistration struct {
ID string `json:",omitempty"` ID string `json:",omitempty"`
Name string `json:",omitempty"` Name string `json:",omitempty"`
Tags []string `json:",omitempty"` Tags []string `json:",omitempty"`
Port int `json:",omitempty"` Port int `json:",omitempty"`
Check *AgentServiceCheck Address string `json:",omitempty"`
Checks AgentServiceChecks Check *AgentServiceCheck
Checks AgentServiceChecks
} }
// AgentCheckRegistration is used to register a new check // AgentCheckRegistration is used to register a new check

View File

@ -45,9 +45,9 @@ func TestAgent_Services(t *testing.T) {
agent := c.Agent() agent := c.Agent()
reg := &AgentServiceRegistration{ reg := &AgentServiceRegistration{
Name: "foo", Name: "foo",
Tags: []string{"bar", "baz"}, Tags: []string{"bar", "baz"},
Port: 8000, Port: 8000,
Check: &AgentServiceCheck{ Check: &AgentServiceCheck{
TTL: "15s", TTL: "15s",
}, },
@ -77,6 +77,52 @@ func TestAgent_Services(t *testing.T) {
} }
} }
func TestAgent_ServiceAddress(t *testing.T) {
c, s := makeClient(t)
defer s.stop()
agent := c.Agent()
reg1 := &AgentServiceRegistration{
Name: "foo1",
Port: 8000,
Address: "192.168.0.42",
}
reg2 := &AgentServiceRegistration{
Name: "foo2",
Port: 8000,
}
if err := agent.ServiceRegister(reg1); err != nil {
t.Fatalf("err: %v", err)
}
if err := agent.ServiceRegister(reg2); err != nil {
t.Fatalf("err: %v", err)
}
services, err := agent.Services()
if err != nil {
t.Fatalf("err: %v", err)
}
if _, ok := services["foo1"]; !ok {
t.Fatalf("missing service: %v", services)
}
if _, ok := services["foo2"]; !ok {
t.Fatalf("missing service: %v", services)
}
if services["foo1"].Address != "192.168.0.42" {
t.Fatalf("missing Address field in service foo1: %v", services)
}
if services["foo2"].Address != "" {
t.Fatalf("missing Address field in service foo2: %v", services)
}
if err := agent.ServiceDeregister("foo"); err != nil {
t.Fatalf("err: %v", err)
}
}
func TestAgent_Services_MultipleChecks(t *testing.T) { func TestAgent_Services_MultipleChecks(t *testing.T) {
c, s := makeClient(t) c, s := makeClient(t)
defer s.stop() defer s.stop()