Add test case for service Address field

This commit is contained in:
Dr. Stefan Schimanski 2015-01-22 11:50:20 +01:00
parent 1ef12ae24b
commit b46d20727b
1 changed files with 46 additions and 1 deletions

View File

@ -48,7 +48,6 @@ func TestAgent_Services(t *testing.T) {
Name: "foo", Name: "foo",
Tags: []string{"bar", "baz"}, Tags: []string{"bar", "baz"},
Port: 8000, Port: 8000,
Address: "192.168.0.42",
Check: &AgentServiceCheck{ Check: &AgentServiceCheck{
TTL: "15s", TTL: "15s",
}, },
@ -78,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()