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"
policyv1beta1 "k8s.io/api/policy/v1beta1"
@ -41,16 +39,16 @@ const (
var _ = framework.IngressNginxDescribe("[Security] Pod Security Policies", func() {
f := framework.NewDefaultFramework("pod-security-policies")
BeforeEach(func() {
ginkgo.BeforeEach(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"},
@ -60,7 +58,7 @@ var _ = framework.IngressNginxDescribe("[Security] Pod Security Policies", func(
})
_, 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")
// update the deployment just to trigger a rolling update and the use of the security policy
err = framework.UpdateDeployment(f.KubeClientSet, f.Namespace, "nginx-ingress-controller", 1,
@ -72,22 +70,22 @@ var _ = framework.IngressNginxDescribe("[Security] Pod Security Policies", func(
return err
})
Expect(err).NotTo(HaveOccurred(), "unexpected error updating ingress controller deployment flags")
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error updating ingress controller deployment flags")
f.NewEchoDeployment()
})
It("should be running with a Pod Security Policy", func() {
ginkgo.It("should be running with a Pod Security Policy", func() {
f.WaitForNginxConfiguration(
func(cfg string) bool {
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)
})
})