Refactor e2e tests to use testify y httpexpect
This commit is contained in:
parent
046e2d959d
commit
f9624cbe46
80 changed files with 2280 additions and 2631 deletions
|
|
@ -20,8 +20,8 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
|
|
@ -34,11 +34,11 @@ func errorBlockName(upstreamName string, errorCode string) string {
|
|||
var _ = framework.DescribeAnnotation("custom-http-errors", func() {
|
||||
f := framework.NewDefaultFramework("custom-http-errors")
|
||||
|
||||
BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeployment()
|
||||
})
|
||||
|
||||
It("configures Nginx correctly", func() {
|
||||
ginkgo.It("configures Nginx correctly", func() {
|
||||
host := "customerrors.foo.com"
|
||||
|
||||
errorCodes := []string{"404", "500"}
|
||||
|
|
@ -56,25 +56,26 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
|
|||
return strings.Contains(serverConfig, fmt.Sprintf("server_name %s", host))
|
||||
})
|
||||
|
||||
By("turning on proxy_intercept_errors directive")
|
||||
Expect(serverConfig).Should(ContainSubstring("proxy_intercept_errors on;"))
|
||||
ginkgo.By("turning on proxy_intercept_errors directive")
|
||||
assert.Contains(ginkgo.GinkgoT(), serverConfig, "proxy_intercept_errors on;")
|
||||
|
||||
By("configuring error_page directive")
|
||||
ginkgo.By("configuring error_page directive")
|
||||
for _, code := range errorCodes {
|
||||
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("error_page %s = %s", code, errorBlockName("upstream-default-backend", code))))
|
||||
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("error_page %s = %s", code, errorBlockName("upstream-default-backend", code)))
|
||||
}
|
||||
|
||||
By("creating error locations")
|
||||
ginkgo.By("creating error locations")
|
||||
for _, code := range errorCodes {
|
||||
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", code))))
|
||||
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", code)))
|
||||
}
|
||||
|
||||
By("updating configuration when only custom-http-error value changes")
|
||||
ginkgo.By("updating configuration when only custom-http-error value changes")
|
||||
err := framework.UpdateIngress(f.KubeClientSet, f.Namespace, host, func(ingress *networking.Ingress) error {
|
||||
ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/custom-http-errors"] = "503"
|
||||
return nil
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
f.WaitForNginxServer(host, func(sc string) bool {
|
||||
if serverConfig != sc {
|
||||
serverConfig = sc
|
||||
|
|
@ -82,22 +83,23 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
|
|||
}
|
||||
return false
|
||||
})
|
||||
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "503"))))
|
||||
Expect(serverConfig).ShouldNot(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "404"))))
|
||||
Expect(serverConfig).ShouldNot(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "500"))))
|
||||
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "503")))
|
||||
assert.NotContains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "404")))
|
||||
assert.NotContains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "500")))
|
||||
|
||||
By("ignoring duplicate values (503 in this case) per server")
|
||||
ginkgo.By("ignoring duplicate values (503 in this case) per server")
|
||||
annotations["nginx.ingress.kubernetes.io/custom-http-errors"] = "404, 503"
|
||||
ing = framework.NewSingleIngress(fmt.Sprintf("%s-else", host), "/else", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
f.WaitForNginxServer(host, func(sc string) bool {
|
||||
serverConfig = sc
|
||||
return strings.Contains(serverConfig, "location /else")
|
||||
})
|
||||
count := strings.Count(serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "503")))
|
||||
Expect(count).Should(Equal(1))
|
||||
assert.Equal(ginkgo.GinkgoT(), count, 1)
|
||||
|
||||
By("using the custom default-backend from annotation for upstream")
|
||||
ginkgo.By("using the custom default-backend from annotation for upstream")
|
||||
customDefaultBackend := "from-annotation"
|
||||
f.NewEchoDeploymentWithNameAndReplicas(customDefaultBackend, 1)
|
||||
|
||||
|
|
@ -105,7 +107,8 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
|
|||
ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/default-backend"] = customDefaultBackend
|
||||
return nil
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
f.WaitForNginxServer(host, func(sc string) bool {
|
||||
if serverConfig != sc {
|
||||
serverConfig = sc
|
||||
|
|
@ -113,7 +116,7 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
|
|||
}
|
||||
return false
|
||||
})
|
||||
Expect(serverConfig).Should(ContainSubstring(errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503")))
|
||||
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("error_page %s = %s", "503", errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503"))))
|
||||
assert.Contains(ginkgo.GinkgoT(), serverConfig, errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503"))
|
||||
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("error_page %s = %s", "503", errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503")))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue