From acd9efbc40d34f8f117b28ee67a198049223fe0f Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Thu, 22 Jan 2015 11:50:20 +0100 Subject: [PATCH] Add test case for service Address field --- api/agent_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/api/agent_test.go b/api/agent_test.go index 1af8c090d0..84ae5d8d03 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()