diff --git a/api/agent_test.go b/api/agent_test.go index 1af8c090d..84ae5d8d0 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -48,7 +48,6 @@ func TestAgent_Services(t *testing.T) { Name: "foo", Tags: []string{"bar", "baz"}, Port: 8000, - Address: "192.168.0.42", Check: &AgentServiceCheck{ 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) { c, s := makeClient(t) defer s.stop()