Refactor e2e tests to use testify y httpexpect

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-02-19 00:08:56 -03:00
parent 046e2d959d
commit f9624cbe46
80 changed files with 2280 additions and 2631 deletions

View file

@ -19,10 +19,9 @@ package annotations
import (
"fmt"
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -30,42 +29,37 @@ import (
var _ = framework.DescribeAnnotation("server-alias", func() {
f := framework.NewDefaultFramework("alias")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should return status code 200 for host 'foo' and 404 for 'bar'", func() {
ginkgo.It("should return status code 200 for host 'foo' and 404 for 'bar'", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(fmt.Sprintf("host=%v", host))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", "bar").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusNotFound))
Expect(body).Should(ContainSubstring("404 Not Found"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", "bar").
Expect().
Status(http.StatusNotFound).
Body().Contains("404 Not Found")
})
It("should return status code 200 for host 'foo' and 'bar'", func() {
ginkgo.It("should return status code 200 for host 'foo' and 'bar'", func() {
host := "foo"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/server-alias": "bar",
@ -76,19 +70,17 @@ var _ = framework.DescribeAnnotation("server-alias", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})
hosts := []string{"foo", "bar"}
for _, host := range hosts {
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(fmt.Sprintf("host=%v", host))
}
})
})