Skip to content

Commit

Permalink
clean up test to use helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Oct 24, 2023
1 parent 6a1e6c3 commit f8c81b6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/mesh/internal/controllers/xds/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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{
{
Expand All @@ -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{}
Expand Down

0 comments on commit f8c81b6

Please sign in to comment.