Skip to content

Commit

Permalink
Add CORS policy test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Mar 6, 2019
1 parent 9adc069 commit 5fc6913
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pkg/router/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ func TestIstioRouter_HTTPRequestHeaders(t *testing.T) {
t.Fatal(err.Error())
}

// test insert
vs, err := mocks.istioClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
Expand All @@ -207,3 +206,36 @@ func TestIstioRouter_HTTPRequestHeaders(t *testing.T) {
t.Errorf("Got timeout %v wanted %v", timeout, "15000")
}
}

func TestIstioRouter_CORS(t *testing.T) {
mocks := setupfakeClients()
router := &IstioRouter{
logger: mocks.logger,
flaggerClient: mocks.flaggerClient,
istioClient: mocks.istioClient,
kubeClient: mocks.kubeClient,
}

err := router.Sync(mocks.canary)
if err != nil {
t.Fatal(err.Error())
}

vs, err := mocks.istioClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}

if len(vs.Spec.Http) != 1 {
t.Fatalf("Got HTTPRoute %v wanted %v", len(vs.Spec.Http), 1)
}

if vs.Spec.Http[0].CorsPolicy == nil {
t.Fatal("Got not CORS policy")
}

methods := vs.Spec.Http[0].CorsPolicy.AllowMethods
if len(methods) != 2 {
t.Fatalf("Got CORS allow methods %v wanted %v", len(methods), 2)
}
}
6 changes: 6 additions & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func newMockCanary() *v1alpha3.Canary {
},
},
},
CorsPolicy: &istiov1alpha3.CorsPolicy{
AllowMethods: []string{
"GET",
"POST",
},
},
}, CanaryAnalysis: v1alpha3.CanaryAnalysis{
Threshold: 10,
StepWeight: 10,
Expand Down

0 comments on commit 5fc6913

Please sign in to comment.