Add tests for Istio gateways

This commit is contained in:
stefanprodan
2020-02-12 11:21:52 +02:00
parent ea4d9ba58d
commit 4c5b226b4c
2 changed files with 39 additions and 5 deletions

View File

@@ -82,16 +82,20 @@ func TestIstioRouter_Sync(t *testing.T) {
gateways := vsClone.Spec.Gateways
gateways = append(gateways, "test-gateway.istio-system")
vsClone.Spec.Gateways = gateways
totalGateways := len(mocks.canary.Spec.Service.Gateways)
vsGateways, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Update(vsClone)
if err != nil {
t.Fatal(err.Error())
}
if len(vsGateways.Spec.Gateways) != 2 {
t.Errorf("Got Istio VS gateway %v wanted %v", vsGateways.Spec.Gateways, 2)
totalGateways++
if len(vsGateways.Spec.Gateways) != totalGateways {
t.Errorf("Got Istio VS gateway %v wanted %v", vsGateways.Spec.Gateways, totalGateways)
}
// undo change
totalGateways--
err = router.Reconcile(mocks.canary)
if err != nil {
t.Fatal(err.Error())
@@ -102,8 +106,8 @@ func TestIstioRouter_Sync(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
if len(vs.Spec.Gateways) != 1 {
t.Errorf("Got Istio VS gateways %v wanted %v", vs.Spec.Gateways, 1)
if len(vs.Spec.Gateways) != totalGateways {
t.Errorf("Got Istio VS gateways %v wanted %v", vs.Spec.Gateways, totalGateways)
}
}
@@ -438,3 +442,28 @@ func TestIstioRouter_ABTest(t *testing.T) {
t.Errorf("Got mirror %v wanted nil", mirror)
}
}
func TestIstioRouter_GatewayPort(t *testing.T) {
mocks := newFixture()
router := &IstioRouter{
logger: mocks.logger,
flaggerClient: mocks.flaggerClient,
istioClient: mocks.meshClient,
kubeClient: mocks.kubeClient,
}
err := router.Reconcile(mocks.canary)
if err != nil {
t.Fatal(err.Error())
}
vs, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}
port := vs.Spec.Http[0].Route[0].Destination.Port.Number
if port != uint32(mocks.canary.Spec.Service.Port) {
t.Fatalf("Got port %v wanted %v", port, mocks.canary.Spec.Service.Port)
}
}

View File

@@ -113,7 +113,8 @@ func newMockCanary() *flaggerv1.Canary {
Kind: "Deployment",
},
Service: flaggerv1.CanaryService{
Port: 9898,
Port: 9898,
PortDiscovery: true,
Headers: &istiov1alpha3.Headers{
Request: &istiov1alpha3.HeaderOperations{
Add: map[string]string{
@@ -136,6 +137,10 @@ func newMockCanary() *flaggerv1.Canary {
Attempts: 10,
PerTryTimeout: "30s",
},
Gateways: []string{
"public-gateway.istio",
"mesh",
},
}, CanaryAnalysis: flaggerv1.CanaryAnalysis{
Threshold: 10,
StepWeight: 10,