diff --git a/pkg/router/appmesh_test.go b/pkg/router/appmesh_test.go index 56e1bdd8..003b127b 100644 --- a/pkg/router/appmesh_test.go +++ b/pkg/router/appmesh_test.go @@ -184,3 +184,45 @@ func TestAppmeshRouter_GetSetRoutes(t *testing.T) { t.Errorf("Got mirror %v wanted %v", m, false) } } + +func TestAppmeshRouter_ABTest(t *testing.T) { + mocks := setupfakeClients() + router := &AppMeshRouter{ + logger: mocks.logger, + flaggerClient: mocks.flaggerClient, + appmeshClient: mocks.meshClient, + kubeClient: mocks.kubeClient, + } + + err := router.Reconcile(mocks.abtest) + if err != nil { + t.Fatal(err.Error()) + } + + // check virtual service + vsName := fmt.Sprintf("%s.%s", mocks.abtest.Spec.TargetRef.Name, mocks.abtest.Namespace) + vs, err := router.appmeshClient.AppmeshV1beta1().VirtualServices("default").Get(vsName, metav1.GetOptions{}) + if err != nil { + t.Fatal(err.Error()) + } + + // check virtual service + if len(vs.Spec.Routes) != 2 { + t.Errorf("Got routes %v wanted %v", len(vs.Spec.Routes), 2) + } + + // check headers + if len(vs.Spec.Routes[0].Http.Match.Headers) < 1 { + t.Errorf("Got no http match headers") + } + + header := vs.Spec.Routes[0].Http.Match.Headers[0].Name + if header != "x-user-type" { + t.Errorf("Got http match header %v wanted %v", header, "x-user-type") + } + + exactMatch := *vs.Spec.Routes[0].Http.Match.Headers[0].Match.Exact + if exactMatch != "test" { + t.Errorf("Got http match header exact %v wanted %v", exactMatch, "test") + } +} diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index 67360a60..f781f692 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -77,10 +77,15 @@ func newMockCanaryAppMesh() *flaggerv1.Canary { MaxWeight: 50, Metrics: []flaggerv1.CanaryMetric{ { - Name: "appmesh_requests_total", + Name: "request-success-rate", Threshold: 99, Interval: "1m", }, + { + Name: "request-duration", + Threshold: 500, + Interval: "1m", + }, }, }, }, @@ -122,12 +127,12 @@ func newMockCanary() *flaggerv1.Canary { MaxWeight: 50, Metrics: []flaggerv1.CanaryMetric{ { - Name: "istio_requests_total", + Name: "request-success-rate", Threshold: 99, Interval: "1m", }, { - Name: "istio_request_duration_seconds_bucket", + Name: "request-duration", Threshold: 500, Interval: "1m", }, @@ -158,7 +163,8 @@ func newMockABTest() *flaggerv1.Canary { Kind: "Deployment", }, Service: flaggerv1.CanaryService{ - Port: 9898, + Port: 9898, + MeshName: "global", }, CanaryAnalysis: flaggerv1.CanaryAnalysis{ Threshold: 10, Iterations: 2, @@ -173,12 +179,12 @@ func newMockABTest() *flaggerv1.Canary { }, Metrics: []flaggerv1.CanaryMetric{ { - Name: "istio_requests_total", + Name: "request-success-rate", Threshold: 99, Interval: "1m", }, { - Name: "istio_request_duration_seconds_bucket", + Name: "request-duration", Threshold: 500, Interval: "1m", },