diff --git a/agent/catalog_endpoint_test.go b/agent/catalog_endpoint_test.go index d3af9bf6d..4df9d4275 100644 --- a/agent/catalog_endpoint_test.go +++ b/agent/catalog_endpoint_test.go @@ -810,6 +810,31 @@ func TestCatalogNodeServices(t *testing.T) { } } +func TestCatalogNodeServices_ConnectProxy(t *testing.T) { + t.Parallel() + + assert := assert.New(t) + a := NewTestAgent(t.Name(), "") + defer a.Shutdown() + + // Register + args := structs.TestRegisterRequestProxy(t) + var out struct{} + assert.Nil(a.RPC("Catalog.Register", args, &out)) + + req, _ := http.NewRequest("GET", fmt.Sprintf( + "/v1/catalog/node/%s", args.Node), nil) + resp := httptest.NewRecorder() + obj, err := a.srv.CatalogNodeServices(resp, req) + assert.Nil(err) + assertIndex(t, resp) + + ns := obj.(*structs.NodeServices) + assert.Len(ns.Services, 1) + v := ns.Services[args.Service.Service] + assert.Equal(structs.ServiceKindConnectProxy, v.Kind) +} + func TestCatalogNodeServices_WanTranslation(t *testing.T) { t.Parallel() a1 := NewTestAgent(t.Name(), ` diff --git a/agent/consul/catalog_endpoint_test.go b/agent/consul/catalog_endpoint_test.go index db49875cb..572ff86bb 100644 --- a/agent/consul/catalog_endpoint_test.go +++ b/agent/consul/catalog_endpoint_test.go @@ -1681,6 +1681,37 @@ func TestCatalog_NodeServices(t *testing.T) { } } +func TestCatalog_NodeServices_ConnectProxy(t *testing.T) { + t.Parallel() + + assert := assert.New(t) + dir1, s1 := testServer(t) + defer os.RemoveAll(dir1) + defer s1.Shutdown() + codec := rpcClient(t, s1) + defer codec.Close() + + testrpc.WaitForLeader(t, s1.RPC, "dc1") + + // Register the service + args := structs.TestRegisterRequestProxy(t) + var out struct{} + assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out)) + + // List + req := structs.NodeSpecificRequest{ + Datacenter: "dc1", + Node: args.Node, + } + var resp structs.IndexedNodeServices + assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.NodeServices", &req, &resp)) + + assert.Len(resp.NodeServices.Services, 1) + v := resp.NodeServices.Services[args.Service.Service] + assert.Equal(structs.ServiceKindConnectProxy, v.Kind) + assert.Equal(args.Service.ProxyDestination, v.ProxyDestination) +} + // Used to check for a regression against a known bug func TestCatalog_Register_FailedCase1(t *testing.T) { t.Parallel()