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

@ -17,13 +17,10 @@ limitations under the License.
package servicebackend
import (
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
corev1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -35,7 +32,7 @@ import (
var _ = framework.IngressNginxDescribe("[Service] backend status code 503", func() {
f := framework.NewDefaultFramework("service-backend")
It("should return 503 when backend service does not exist", func() {
ginkgo.It("should return 503 when backend service does not exist", func() {
host := "nonexistent.svc.com"
bi := buildIngressWithNonexistentService(host, f.Namespace, "/")
@ -46,15 +43,14 @@ var _ = framework.IngressNginxDescribe("[Service] backend status code 503", func
return strings.Contains(server, "proxy_pass http://upstream_balancer;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(503))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusServiceUnavailable)
})
It("should return 503 when all backend service endpoints are unavailable", func() {
ginkgo.It("should return 503 when all backend service endpoints are unavailable", func() {
host := "unavailable.svc.com"
bi, bs := buildIngressWithUnavailableServiceEndpoints(host, f.Namespace, "/")
@ -67,14 +63,12 @@ var _ = framework.IngressNginxDescribe("[Service] backend status code 503", func
return strings.Contains(server, "proxy_pass http://upstream_balancer;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(503))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusServiceUnavailable)
})
})
func buildIngressWithNonexistentService(host, namespace, path string) *networking.Ingress {

View file

@ -17,13 +17,10 @@ limitations under the License.
package servicebackend
import (
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
core "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -35,7 +32,7 @@ import (
var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
f := framework.NewDefaultFramework("type-externalname")
It("works with external name set to incomplete fdqn", func() {
ginkgo.It("works with external name set to incomplete fdqn", func() {
f.NewEchoDeployment()
host := "echo"
@ -61,15 +58,14 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
return strings.Contains(server, "proxy_pass http://upstream_balancer;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/get").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(200))
f.HTTPTestClient().
GET("/get").
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
It("should return 200 for service type=ExternalName without a port defined", func() {
ginkgo.It("should return 200 for service type=ExternalName without a port defined", func() {
host := "echo"
svc := &core.Service{
@ -93,15 +89,14 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
return strings.Contains(server, "proxy_pass http://upstream_balancer;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/get").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(200))
f.HTTPTestClient().
GET("/get").
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
It("should return 200 for service type=ExternalName with a port defined", func() {
ginkgo.It("should return 200 for service type=ExternalName with a port defined", func() {
host := "echo"
svc := &core.Service{
@ -132,15 +127,14 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
return strings.Contains(server, "proxy_pass http://upstream_balancer;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/get").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(200))
f.HTTPTestClient().
GET("/get").
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
It("should return status 502 for service type=ExternalName with an invalid host", func() {
ginkgo.It("should return status 502 for service type=ExternalName with an invalid host", func() {
host := "echo"
svc := &core.Service{
@ -164,15 +158,14 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
return strings.Contains(server, "proxy_pass http://upstream_balancer;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/get").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(502))
f.HTTPTestClient().
GET("/get").
WithHeader("Host", host).
Expect().
Status(http.StatusBadGateway)
})
It("should return 200 for service type=ExternalName using a port name", func() {
ginkgo.It("should return 200 for service type=ExternalName using a port name", func() {
host := "echo"
svc := &core.Service{
@ -204,12 +197,10 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
return strings.Contains(server, "proxy_pass http://upstream_balancer;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/get").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(200))
f.HTTPTestClient().
GET("/get").
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
})