Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: nbn01 <nandan_bn@intuit.com>
  • Loading branch information
nbn01 committed Apr 1, 2022
1 parent 42f513c commit c97ed13
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions admiral/pkg/clusters/serviceentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,83 @@ func TestCreateServiceEntryForBlueGreenRolloutsUsecase(t *testing.T) {
}
}

func TestUpdateEndpointsForBlueGreen(t *testing.T) {
const CLUSTER_INGRESS_1 = "ingress1.com"
const ACTIVE_SERVICE = "activeService"
const PREVIEW_SERVICE = "previewService"
const NAMESPACE = "namespace"
const ACTIVE_MESH_HOST = "qal.example.mesh"
const PREVIEW_MESH_HOST = "preview.qal.example.mesh"

rollout := argo.Rollout{}
rollout.Spec.Strategy = argo.RolloutStrategy{
BlueGreen: &argo.BlueGreenStrategy{
ActiveService: ACTIVE_SERVICE,
PreviewService: PREVIEW_SERVICE,
},
}
rollout.Spec.Template.Annotations = map[string]string{}
rollout.Spec.Template.Annotations[common.SidecarEnabledPorts] = "8080"

endpoint := istionetworkingv1alpha3.ServiceEntry_Endpoint{
Labels: map[string]string{}, Address: CLUSTER_INGRESS_1, Ports: map[string]uint32{"http": 15443},
}

meshPorts := map[string]uint32{"http": 8080}

weightedServices := map[string]*WeightedService{
ACTIVE_SERVICE: {Service: &v1.Service{ObjectMeta: v12.ObjectMeta{Name: ACTIVE_SERVICE, Namespace: NAMESPACE}}},
PREVIEW_SERVICE: {Service: &v1.Service{ObjectMeta: v12.ObjectMeta{Name: PREVIEW_SERVICE, Namespace: NAMESPACE}}},
}

activeWantedEndpoints := istionetworkingv1alpha3.ServiceEntry_Endpoint{
Address: ACTIVE_SERVICE + common.Sep + NAMESPACE + common.DotLocalDomainSuffix, Ports: meshPorts,
}

previewWantedEndpoints := istionetworkingv1alpha3.ServiceEntry_Endpoint{
Address: PREVIEW_SERVICE + common.Sep + NAMESPACE + common.DotLocalDomainSuffix, Ports: meshPorts,
}

testCases := []struct {
name string
rollout argo.Rollout
inputEndpoint istionetworkingv1alpha3.ServiceEntry_Endpoint
weightedServices map[string]*WeightedService
clusterIngress string
meshPorts map[string]uint32
meshHost string
wantedEndpoints istionetworkingv1alpha3.ServiceEntry_Endpoint
}{
{
name: "should return endpoint with active service address",
rollout: rollout,
inputEndpoint: endpoint,
weightedServices: weightedServices,
meshPorts: meshPorts,
meshHost: ACTIVE_MESH_HOST,
wantedEndpoints: activeWantedEndpoints,
},
{
name: "should return endpoint with preview service address",
rollout: rollout,
inputEndpoint: endpoint,
weightedServices: weightedServices,
meshPorts: meshPorts,
meshHost: PREVIEW_MESH_HOST,
wantedEndpoints: previewWantedEndpoints,
},
}

for _, c := range testCases {
t.Run(c.name, func(t *testing.T) {
updateEndpointsForBlueGreen(&c.rollout, c.weightedServices, map[string]string{}, &c.inputEndpoint, "test", c.meshHost)
if c.inputEndpoint.Address != c.wantedEndpoints.Address {
t.Errorf("Wanted %s endpoint, got: %s", c.wantedEndpoints.Address, c.inputEndpoint.Address)
}
})
}
}

func TestUpdateEndpointsForWeightedServices(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit c97ed13

Please sign in to comment.