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

@ -20,10 +20,8 @@ import (
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
@ -37,16 +35,16 @@ import (
var _ = framework.IngressNginxDescribe("[Security] Pod Security Policies with volumes", func() {
f := framework.NewDefaultFramework("pod-security-policies-volumes")
It("should be running with a Pod Security Policy", func() {
ginkgo.It("should be running with a Pod Security Policy", func() {
psp := createPodSecurityPolicy()
_, err := f.KubeClientSet.PolicyV1beta1().PodSecurityPolicies().Create(psp)
if !k8sErrors.IsAlreadyExists(err) {
Expect(err).NotTo(HaveOccurred(), "creating Pod Security Policy")
assert.Nil(ginkgo.GinkgoT(), err, "creating Pod Security Policy")
}
role, err := f.KubeClientSet.RbacV1().Roles(f.Namespace).Get("nginx-ingress-controller", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred(), "getting ingress controller cluster role")
Expect(role).NotTo(BeNil())
assert.Nil(ginkgo.GinkgoT(), err, "getting ingress controller cluster role")
assert.NotNil(ginkgo.GinkgoT(), role)
role.Rules = append(role.Rules, rbacv1.PolicyRule{
APIGroups: []string{"policy"},
@ -56,7 +54,7 @@ var _ = framework.IngressNginxDescribe("[Security] Pod Security Policies with vo
})
_, err = f.KubeClientSet.RbacV1().Roles(f.Namespace).Update(role)
Expect(err).NotTo(HaveOccurred(), "updating ingress controller cluster role to use a pod security policy")
assert.Nil(ginkgo.GinkgoT(), err, "updating ingress controller cluster role to use a pod security policy")
err = framework.UpdateDeployment(f.KubeClientSet, f.Namespace, "nginx-ingress-controller", 1,
func(deployment *appsv1.Deployment) error {
@ -95,7 +93,7 @@ var _ = framework.IngressNginxDescribe("[Security] Pod Security Policies with vo
return err
})
Expect(err).NotTo(HaveOccurred(), "unexpected error updating ingress controller deployment")
assert.Nil(ginkgo.GinkgoT(), err, "updating ingress controller deployment")
f.NewEchoDeployment()
@ -104,10 +102,10 @@ var _ = framework.IngressNginxDescribe("[Security] Pod Security Policies with vo
return strings.Contains(cfg, "server_tokens on")
})
resp, _, _ := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", "foo.bar.com").
End()
Expect(resp.StatusCode).Should(Equal(http.StatusNotFound))
f.HTTPTestClient().
GET("/").
WithHeader("Host", "foo.bar.com").
Expect().
Status(http.StatusNotFound)
})
})