Skip to content

Commit 4c5b226

Browse files
committed
Add tests for Istio gateways
1 parent ea4d9ba commit 4c5b226

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

pkg/router/istio_test.go

+33-4
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,20 @@ func TestIstioRouter_Sync(t *testing.T) {
8282
gateways := vsClone.Spec.Gateways
8383
gateways = append(gateways, "test-gateway.istio-system")
8484
vsClone.Spec.Gateways = gateways
85+
totalGateways := len(mocks.canary.Spec.Service.Gateways)
8586

8687
vsGateways, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Update(vsClone)
8788
if err != nil {
8889
t.Fatal(err.Error())
8990
}
90-
if len(vsGateways.Spec.Gateways) != 2 {
91-
t.Errorf("Got Istio VS gateway %v wanted %v", vsGateways.Spec.Gateways, 2)
91+
92+
totalGateways++
93+
if len(vsGateways.Spec.Gateways) != totalGateways {
94+
t.Errorf("Got Istio VS gateway %v wanted %v", vsGateways.Spec.Gateways, totalGateways)
9295
}
9396

9497
// undo change
98+
totalGateways--
9599
err = router.Reconcile(mocks.canary)
96100
if err != nil {
97101
t.Fatal(err.Error())
@@ -102,8 +106,8 @@ func TestIstioRouter_Sync(t *testing.T) {
102106
if err != nil {
103107
t.Fatal(err.Error())
104108
}
105-
if len(vs.Spec.Gateways) != 1 {
106-
t.Errorf("Got Istio VS gateways %v wanted %v", vs.Spec.Gateways, 1)
109+
if len(vs.Spec.Gateways) != totalGateways {
110+
t.Errorf("Got Istio VS gateways %v wanted %v", vs.Spec.Gateways, totalGateways)
107111
}
108112
}
109113

@@ -438,3 +442,28 @@ func TestIstioRouter_ABTest(t *testing.T) {
438442
t.Errorf("Got mirror %v wanted nil", mirror)
439443
}
440444
}
445+
446+
func TestIstioRouter_GatewayPort(t *testing.T) {
447+
mocks := newFixture()
448+
router := &IstioRouter{
449+
logger: mocks.logger,
450+
flaggerClient: mocks.flaggerClient,
451+
istioClient: mocks.meshClient,
452+
kubeClient: mocks.kubeClient,
453+
}
454+
455+
err := router.Reconcile(mocks.canary)
456+
if err != nil {
457+
t.Fatal(err.Error())
458+
}
459+
460+
vs, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
461+
if err != nil {
462+
t.Fatal(err.Error())
463+
}
464+
465+
port := vs.Spec.Http[0].Route[0].Destination.Port.Number
466+
if port != uint32(mocks.canary.Spec.Service.Port) {
467+
t.Fatalf("Got port %v wanted %v", port, mocks.canary.Spec.Service.Port)
468+
}
469+
}

pkg/router/router_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ func newMockCanary() *flaggerv1.Canary {
113113
Kind: "Deployment",
114114
},
115115
Service: flaggerv1.CanaryService{
116-
Port: 9898,
116+
Port: 9898,
117+
PortDiscovery: true,
117118
Headers: &istiov1alpha3.Headers{
118119
Request: &istiov1alpha3.HeaderOperations{
119120
Add: map[string]string{
@@ -136,6 +137,10 @@ func newMockCanary() *flaggerv1.Canary {
136137
Attempts: 10,
137138
PerTryTimeout: "30s",
138139
},
140+
Gateways: []string{
141+
"public-gateway.istio",
142+
"mesh",
143+
},
139144
}, CanaryAnalysis: flaggerv1.CanaryAnalysis{
140145
Threshold: 10,
141146
StepWeight: 10,

0 commit comments

Comments
 (0)