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

@ -23,10 +23,8 @@ import (
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
pool "gopkg.in/go-playground/pool.v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -36,7 +34,7 @@ import (
var _ = framework.IngressNginxDescribe("[Memory Leak] Dynamic Certificates", func() {
f := framework.NewDefaultFramework("lua-dynamic-certificates")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
@ -44,11 +42,11 @@ var _ = framework.IngressNginxDescribe("[Memory Leak] Dynamic Certificates", fun
hostCount := 1000
iterations := 10
By("Waiting a minute before starting the test")
ginkgo.By("Waiting a minute before starting the test")
time.Sleep(1 * time.Minute)
for iteration := 1; iteration <= iterations; iteration++ {
By(fmt.Sprintf("Running iteration %v", iteration))
ginkgo.By(fmt.Sprintf("Running iteration %v", iteration))
p := pool.NewLimited(200)
@ -64,7 +62,7 @@ var _ = framework.IngressNginxDescribe("[Memory Leak] Dynamic Certificates", fun
p.Close()
By("waiting one minute before next iteration")
ginkgo.By("waiting one minute before next iteration")
time.Sleep(1 * time.Minute)
}
})
@ -76,7 +74,7 @@ func privisionIngress(hostname string, f *framework.Framework) {
ing.Spec.TLS[0].Hosts,
ing.Spec.TLS[0].SecretName,
ing.Namespace)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
f.WaitForNginxServer(hostname,
func(server string) bool {
@ -86,23 +84,26 @@ func privisionIngress(hostname string, f *framework.Framework) {
}
func checkIngress(hostname string, f *framework.Framework) {
req := gorequest.New()
resp, _, errs := req.
Get(f.GetURL(framework.HTTPS)).
TLSClientConfig(&tls.Config{ServerName: hostname, InsecureSkipVerify: true}).
Set("Host", hostname).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
resp := f.HTTPTestClientWithTLSConfig(&tls.Config{
ServerName: hostname,
InsecureSkipVerify: true,
}).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", hostname).
Expect().
Raw()
assert.Equal(ginkgo.GinkgoT(), resp.StatusCode, http.StatusOK)
// check the returned secret is not the fake one
cert := resp.TLS.PeerCertificates[0]
Expect(cert.DNSNames[0]).Should(Equal(hostname))
assert.Equal(ginkgo.GinkgoT(), cert.DNSNames[0], hostname)
}
func deleteIngress(hostname string, f *framework.Framework) {
err := f.KubeClientSet.NetworkingV1beta1().Ingresses(f.Namespace).Delete(hostname, &metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred(), "unexpected error deleting ingress")
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error deleting ingress")
}
func run(host string, f *framework.Framework) pool.WorkFunc {
@ -111,15 +112,15 @@ func run(host string, f *framework.Framework) pool.WorkFunc {
return nil, nil
}
By(fmt.Sprintf("\tcreating ingress for host %v", host))
ginkgo.By(fmt.Sprintf("\tcreating ingress for host %v", host))
privisionIngress(host, f)
time.Sleep(100 * time.Millisecond)
By(fmt.Sprintf("\tchecking ingress for host %v", host))
ginkgo.By(fmt.Sprintf("\tchecking ingress for host %v", host))
checkIngress(host, f)
By(fmt.Sprintf("\tdestroying ingress for host %v", host))
ginkgo.By(fmt.Sprintf("\tdestroying ingress for host %v", host))
deleteIngress(host, f)
return true, nil