From f8c81b61208fd6cc8c6c8caf05aa8dff78ba301a Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 16 Oct 2023 16:18:44 -0600 Subject: [PATCH] clean up test to use helper. --- .../controllers/xds/controller_test.go | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/mesh/internal/controllers/xds/controller_test.go b/internal/mesh/internal/controllers/xds/controller_test.go index eb406ec423f2..7d5076573fb8 100644 --- a/internal/mesh/internal/controllers/xds/controller_test.go +++ b/internal/mesh/internal/controllers/xds/controller_test.go @@ -1080,11 +1080,16 @@ func (suite *xdsControllerTestSuite) addRequiredEndpointsAndRefs(pst *pbmesh.Pro var vp uint32 = 7000 requiredEps := make(map[string]*pbproxystate.EndpointRef) +<<<<<<< HEAD // get service name and ports +======= + // iterate through clusters and set up endpoints for cluster/mesh port. +>>>>>>> 158caa2516 (clean up test to use helper.) for clusterName := range pst.ProxyState.Clusters { if clusterName == "null_route_cluster" || clusterName == "original-destination" { continue } +<<<<<<< HEAD vp++ separator := "." if proxyType == "source" { @@ -1093,16 +1098,33 @@ func (suite *xdsControllerTestSuite) addRequiredEndpointsAndRefs(pst *pbmesh.Pro clusterNameSplit := strings.Split(clusterName, separator) port := clusterNameSplit[0] svcName := clusterNameSplit[1] +======= + //increment the random port number. + vp++ + clusterNameSplit := strings.Split(clusterName, ".") + port := clusterNameSplit[0] + svcName := clusterNameSplit[1] + + // set up service data with port info. +>>>>>>> 158caa2516 (clean up test to use helper.) serviceData.Ports = append(serviceData.Ports, &pbcatalog.ServicePort{ TargetPort: port, VirtualPort: vp, Protocol: pbcatalog.Protocol_PROTOCOL_TCP, }) +<<<<<<< HEAD +======= + // create service. +>>>>>>> 158caa2516 (clean up test to use helper.) svc := resourcetest.Resource(pbcatalog.ServiceType, svcName). WithData(suite.T(), &pbcatalog.Service{}). Write(suite.T(), suite.client) +<<<<<<< HEAD +======= + // create endpoints with svc as owner. +>>>>>>> 158caa2516 (clean up test to use helper.) eps := resourcetest.Resource(pbcatalog.ServiceEndpointsType, svcName). WithData(suite.T(), &pbcatalog.ServiceEndpoints{Endpoints: []*pbcatalog.Endpoint{ { @@ -1122,14 +1144,18 @@ func (suite *xdsControllerTestSuite) addRequiredEndpointsAndRefs(pst *pbmesh.Pro }}). WithOwner(svc.Id). Write(suite.T(), suite.client) + + // add to working list of required endpoints. requiredEps[clusterName] = &pbproxystate.EndpointRef{ Id: eps.Id, Port: "mesh", } } + // set working list of required endpoints as proxy state's RequiredEndpoints. pst.RequiredEndpoints = requiredEps } + func JSONToProxyTemplate(t *testing.T, json []byte) *pbmesh.ProxyStateTemplate { t.Helper() proxyTemplate := &pbmesh.ProxyStateTemplate{}