From 6cd9e0e37c450f6451d62ea28826cad3da0f6d7a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 Mar 2018 10:54:05 -0800 Subject: [PATCH] agent: /v1/agent/services test with connect proxies (works w/ no change) --- agent/agent_endpoint_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/agent/agent_endpoint_test.go b/agent/agent_endpoint_test.go index 1a62a8427..126994196 100644 --- a/agent/agent_endpoint_test.go +++ b/agent/agent_endpoint_test.go @@ -23,6 +23,7 @@ import ( "github.com/hashicorp/consul/types" "github.com/hashicorp/serf/serf" "github.com/pascaldekloe/goe/verify" + "github.com/stretchr/testify/assert" ) func makeReadOnlyAgentACL(t *testing.T, srv *HTTPServer) string { @@ -68,6 +69,32 @@ func TestAgent_Services(t *testing.T) { } } +func TestAgent_Services_ConnectProxy(t *testing.T) { + t.Parallel() + + assert := assert.New(t) + a := NewTestAgent(t.Name(), "") + defer a.Shutdown() + + srv1 := &structs.NodeService{ + Kind: structs.ServiceKindConnectProxy, + ID: structs.ConnectProxyServiceName, + Service: structs.ConnectProxyServiceName, + Port: 5000, + ProxyDestination: "db", + } + a.State.AddService(srv1, "") + + req, _ := http.NewRequest("GET", "/v1/agent/services", nil) + obj, err := a.srv.AgentServices(nil, req) + assert.Nil(err) + val := obj.(map[string]*structs.NodeService) + assert.Len(val, 1) + actual := val[structs.ConnectProxyServiceName] + assert.Equal(structs.ServiceKindConnectProxy, actual.Kind) + assert.Equal("db", actual.ProxyDestination) +} + func TestAgent_Services_ACLFilter(t *testing.T) { t.Parallel() a := NewTestAgent(t.Name(), TestACLConfig())