Add request header add test

This commit is contained in:
stefanprodan
2019-03-06 13:46:19 +02:00
parent eab7f126a6
commit 1d4dfb0883
2 changed files with 38 additions and 0 deletions
+30
View File
@@ -177,3 +177,33 @@ func TestIstioRouter_GetRoutes(t *testing.T) {
t.Errorf("Got canary weight %v wanted %v", c, 0)
}
}
func TestIstioRouter_HTTPRequestHeaders(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())
}
// test insert
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)
}
timeout := vs.Spec.Http[0].AppendHeaders["x-envoy-upstream-rq-timeout-ms"]
if timeout != "15000" {
t.Errorf("Got timeout %v wanted %v", timeout, "15000")
}
}
+8
View File
@@ -2,6 +2,7 @@ package router
import (
"github.com/stefanprodan/flagger/pkg/apis/flagger/v1alpha3"
istiov1alpha3 "github.com/stefanprodan/flagger/pkg/apis/istio/v1alpha3"
clientset "github.com/stefanprodan/flagger/pkg/client/clientset/versioned"
fakeFlagger "github.com/stefanprodan/flagger/pkg/client/clientset/versioned/fake"
"github.com/stefanprodan/flagger/pkg/logging"
@@ -57,6 +58,13 @@ func newMockCanary() *v1alpha3.Canary {
},
Service: v1alpha3.CanaryService{
Port: 9898,
Headers: &istiov1alpha3.Headers{
Request: &istiov1alpha3.HeaderOperations{
Set: map[string]string{
"x-envoy-upstream-rq-timeout-ms": "15000",
},
},
},
}, CanaryAnalysis: v1alpha3.CanaryAnalysis{
Threshold: 10,
StepWeight: 10,