Add App Mesh http match headers tests

This commit is contained in:
stefanprodan
2019-10-16 15:43:26 +03:00
parent 00155aff37
commit 03652dc631
2 changed files with 54 additions and 6 deletions
+42
View File
@@ -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")
}
}
+12 -6
View File
@@ -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",
},