Add unit tests for Contour prefix, timeout and retries

This commit is contained in:
stefanprodan
2019-12-19 19:06:47 +02:00
parent bb4591106a
commit 851c6701b3
2 changed files with 26 additions and 2 deletions
+17 -2
View File
@@ -39,7 +39,7 @@ func TestContourRouter_Reconcile(t *testing.T) {
t.Errorf("Canary weight should is %v wanted 0", services[0].Weight)
}
// test port update
// test update
cd, err := mocks.flaggerClient.FlaggerV1alpha3().Canaries("default").Get("podinfo", metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
@@ -47,6 +47,7 @@ func TestContourRouter_Reconcile(t *testing.T) {
cdClone := cd.DeepCopy()
cdClone.Spec.Service.Port = 8080
cdClone.Spec.Service.Timeout = "1m"
canary, err := mocks.flaggerClient.FlaggerV1alpha3().Canaries("default").Update(cdClone)
if err != nil {
t.Fatal(err.Error())
@@ -64,11 +65,25 @@ func TestContourRouter_Reconcile(t *testing.T) {
}
port := proxy.Spec.Routes[0].Services[0].Port
if port != 8080 {
t.Errorf("Service port is %v wanted %v", port, 8080)
}
timeout := proxy.Spec.Routes[0].TimeoutPolicy.Response
if timeout != "1m" {
t.Errorf("HTTPProxy timeout is %v wanted %v", timeout, "1m")
}
prefix := proxy.Spec.Routes[0].Conditions[0].Prefix
if prefix != "/podinfo" {
t.Errorf("HTTPProxy prefix is %v wanted %v", prefix, "podinfo")
}
retry := proxy.Spec.Routes[0].RetryPolicy.NumRetries
if retry != 10 {
t.Errorf("HTTPProxy NumRetries is %v wanted %v", retry, 10)
}
// test headers update
cd, err = mocks.flaggerClient.FlaggerV1alpha3().Canaries("default").Get("podinfo", metav1.GetOptions{})
if err != nil {
+9
View File
@@ -128,6 +128,15 @@ func newMockCanary() *flaggerv1.Canary {
"POST",
},
},
Match: []istiov1alpha3.HTTPMatchRequest{
{Uri: &istiov1alpha1.StringMatch{
Prefix: "/podinfo",
}},
},
Retries: &istiov1alpha3.HTTPRetry{
Attempts: 10,
PerTryTimeout: "30s",
},
}, CanaryAnalysis: flaggerv1.CanaryAnalysis{
Threshold: 10,
StepWeight: 10,