Refactor assertions

This commit is contained in:
Manuel Alejandro de Brito Fontes 2018-11-18 10:53:05 -03:00
parent af2dce901d
commit a51136b863
18 changed files with 46 additions and 46 deletions

View file

@ -68,7 +68,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
match := md5Regex.FindStringSubmatch(resp.Header.Get("Set-Cookie"))
Expect(len(match)).Should(BeNumerically("==", 1))
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring(match[0]))
})
@ -97,7 +97,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
match := sha1Regex.FindStringSubmatch(resp.Header.Get("Set-Cookie"))
Expect(len(match)).Should(BeNumerically("==", 1))
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring(match[0]))
})
@ -122,7 +122,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/something"))
})
@ -179,7 +179,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/something;"))
@ -188,7 +188,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/somewhereelese;"))
})
@ -215,7 +215,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
local, _ := time.LoadLocation("GMT")
duration, _ := time.ParseDuration("48h")

View file

@ -55,7 +55,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Alias", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
@ -64,7 +64,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Alias", func() {
Set("Host", "bar").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusNotFound))
Expect(body).Should(ContainSubstring("404 Not Found"))
})
@ -91,7 +91,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Alias", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
}

View file

@ -59,7 +59,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Approot", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
Expect(resp.Header.Get("Location")).Should(Equal("http://approot.bar.com/foo"))
})

View file

@ -63,7 +63,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
})
@ -91,7 +91,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusServiceUnavailable))
Expect(body).Should(ContainSubstring("503 Service Temporarily Unavailable"))
})
@ -122,7 +122,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
Expect(body).Should(ContainSubstring("401 Authorization Required"))
})
@ -154,7 +154,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() {
SetBasicAuth("user", "pass").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
Expect(body).Should(ContainSubstring("401 Authorization Required"))
})
@ -186,7 +186,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() {
SetBasicAuth("foo", "bar").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
})
@ -229,7 +229,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() {
SetBasicAuth("foo", "bar").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusInternalServerError))
})

View file

@ -81,7 +81,7 @@ var _ = framework.IngressNginxDescribe("Annotations - AuthTLS", func() {
TLSClientConfig(&tls.Config{ServerName: host, InsecureSkipVerify: true}).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusBadRequest))
// Send Request Passing the Client Certs
@ -90,7 +90,7 @@ var _ = framework.IngressNginxDescribe("Annotations - AuthTLS", func() {
TLSClientConfig(clientConfig).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
})
@ -135,7 +135,7 @@ var _ = framework.IngressNginxDescribe("Annotations - AuthTLS", func() {
TLSClientConfig(&tls.Config{ServerName: host, InsecureSkipVerify: true}).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
})
@ -191,7 +191,7 @@ var _ = framework.IngressNginxDescribe("Annotations - AuthTLS", func() {
Set("Host", host).
RedirectPolicy(noRedirectPolicyFunc).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
Expect(resp.Header.Get("Location")).Should(Equal(f.IngressController.HTTPURL + errorPath))
@ -201,7 +201,7 @@ var _ = framework.IngressNginxDescribe("Annotations - AuthTLS", func() {
TLSClientConfig(clientConfig).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
})
})

View file

@ -76,7 +76,7 @@ var _ = framework.IngressNginxDescribe("Annotations - canary", func() {
Set("CanaryByHeader", "always").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).ShouldNot(Equal(http.StatusNotFound))
Expect(body).Should(ContainSubstring("http-svc-canary"))
})
@ -113,7 +113,7 @@ var _ = framework.IngressNginxDescribe("Annotations - canary", func() {
Set("CanaryByHeader", "never").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).ShouldNot(Equal(http.StatusNotFound))
Expect(body).ShouldNot(ContainSubstring("http-svc-canary"))
})
@ -152,7 +152,7 @@ var _ = framework.IngressNginxDescribe("Annotations - canary", func() {
AddCookie(&http.Cookie{Name: "CanaryByCookie", Value: "always"}).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).ShouldNot(Equal(http.StatusNotFound))
Expect(body).Should(ContainSubstring("http-svc-canary"))
})
@ -191,7 +191,7 @@ var _ = framework.IngressNginxDescribe("Annotations - canary", func() {
AddCookie(&http.Cookie{Name: "CanaryByCookie", Value: "never"}).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).ShouldNot(Equal(http.StatusNotFound))
Expect(body).ShouldNot(ContainSubstring("http-svc-canary"))
})

View file

@ -57,7 +57,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Connection", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("connection=keep-alive")))
})

View file

@ -75,7 +75,7 @@ var _ = framework.IngressNginxDescribe("Annotations - CORS", func() {
Options(f.IngressController.HTTPURL+uri).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusNoContent))
})

View file

@ -58,7 +58,7 @@ var _ = framework.IngressNginxDescribe("Annotations - custom default-backend", f
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).To(ContainSubstring("x-code=503"))

View file

@ -59,7 +59,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Forcesslredirect", func()
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect))
Expect(resp.Header.Get("Location")).Should(Equal("https://forcesslredirect.bar.com/"))
})

View file

@ -63,7 +63,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Fromtowwwredirect", func()
Set("Host", fmt.Sprintf("%s.%s", "www", host)).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect))
Expect(resp.Header.Get("Location")).Should(Equal("http://fromtowwwredirect.bar.com/foo"))
})

View file

@ -94,7 +94,7 @@ var _ = framework.IngressNginxDescribe("Default backend", func() {
}
resp, _, errs := cm.End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(test.Status))
}
})

View file

@ -44,7 +44,7 @@ var _ = framework.IngressNginxDescribe("Default backend - SSL", func() {
InsecureSkipVerify: true,
}).End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(len(resp.TLS.PeerCertificates)).Should(BeNumerically("==", 1))
for _, pc := range resp.TLS.PeerCertificates {
@ -59,7 +59,7 @@ var _ = framework.IngressNginxDescribe("Default backend - SSL", func() {
InsecureSkipVerify: true,
}).
Set("Host", "foo.bar.com").End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(len(resp.TLS.PeerCertificates)).Should(BeNumerically("==", 1))
for _, pc := range resp.TLS.PeerCertificates {
Expect(pc.Issuer.CommonName).Should(Equal("Kubernetes Ingress Controller Fake Certificate"))

View file

@ -56,7 +56,7 @@ var _ = framework.IngressNginxDescribe("Service backend - 503", func() {
Get(f.IngressController.HTTPURL).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(503))
})
@ -79,7 +79,7 @@ var _ = framework.IngressNginxDescribe("Service backend - 503", func() {
Get(f.IngressController.HTTPURL).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(503))
})

View file

@ -63,7 +63,7 @@ var _ = framework.IngressNginxDescribe("X-Forwarded headers", func() {
Set("X-Forwarded-Host", "myhost").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=myhost")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-host=myhost")))
@ -92,7 +92,7 @@ var _ = framework.IngressNginxDescribe("X-Forwarded headers", func() {
Set("X-Forwarded-Host", "myhost").
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=forwarded-headers")))
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=80")))

View file

@ -67,7 +67,7 @@ var _ = framework.IngressNginxDescribe("No Auth locations", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
Expect(body).Should(ContainSubstring("401 Authorization Required"))
})
@ -84,7 +84,7 @@ var _ = framework.IngressNginxDescribe("No Auth locations", func() {
SetBasicAuth(username, password).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
})
@ -99,7 +99,7 @@ var _ = framework.IngressNginxDescribe("No Auth locations", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
})
})

View file

@ -67,7 +67,7 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.TLS.Version).Should(BeNumerically("==", tls.VersionTLS12))
Expect(resp.TLS.CipherSuite).Should(BeNumerically("==", tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384))
@ -86,7 +86,7 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.TLS.Version).Should(BeNumerically("==", tls.VersionTLS10))
Expect(resp.TLS.CipherSuite).Should(BeNumerically("==", tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA))
@ -116,7 +116,7 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Strict-Transport-Security")).Should(ContainSubstring("max-age=86400"))
@ -134,7 +134,7 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Strict-Transport-Security")).ShouldNot(ContainSubstring("includeSubDomains"))
@ -152,7 +152,7 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() {
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Strict-Transport-Security")).Should(ContainSubstring("preload"))
})

View file

@ -91,7 +91,7 @@ var _ = framework.IngressNginxDescribe("TCP Feature", func() {
resp, _, errs := gorequest.New().
Get(fmt.Sprintf("http://%v:%v", ip, port)).
End()
Expect(len(errs)).Should(BeEmpty())
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(200))
})
})