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,12 +17,11 @@ limitations under the License.
package defaultbackend
import (
"crypto/tls"
"net/http"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
"gopkg.in/gavv/httpexpect.v2"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -30,7 +29,7 @@ import (
var _ = framework.IngressNginxDescribe("[Default Backend]", func() {
f := framework.NewDefaultFramework("default-backend")
It("should return 404 sending requests when only a default backend is running", func() {
ginkgo.It("should return 404 sending requests when only a default backend is running", func() {
testCases := []struct {
Name string
Host string
@ -61,65 +60,55 @@ var _ = framework.IngressNginxDescribe("[Default Backend]", func() {
}
for _, test := range testCases {
By(test.Name)
ginkgo.By(test.Name)
request := gorequest.New()
var cm *gorequest.SuperAgent
var req *httpexpect.Request
switch test.Scheme {
case framework.HTTP:
cm = request.CustomMethod(test.Method, f.GetURL(framework.HTTP))
req = f.HTTPTestClient().Request(test.Method, test.Path)
req.WithURL(f.GetURL(framework.HTTP) + test.Path)
case framework.HTTPS:
cm = request.CustomMethod(test.Method, f.GetURL(framework.HTTPS))
// the default backend uses a self generated certificate
cm.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
req = f.HTTPTestClient().Request(test.Method, test.Path)
req.WithURL(f.GetURL(framework.HTTPS) + test.Path)
default:
Fail("Unexpected request scheme")
ginkgo.Fail("Unexpected request scheme")
}
if test.Host != "" {
cm.Set("Host", test.Host)
req.WithHeader("Host", test.Host)
}
resp, _, errs := cm.End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(test.Status))
req.Expect().
Status(test.Status)
}
})
It("enables access logging for default backend", func() {
ginkgo.It("enables access logging for default backend", func() {
f.UpdateNginxConfigMapData("enable-access-log-for-default-backend", "true")
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/somethingOne").
Set("Host", "foo").
End()
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusNotFound))
f.HTTPTestClient().
GET("/somethingOne").
WithHeader("Host", "foo").
Expect().
Status(http.StatusNotFound)
logs, err := f.NginxLogs()
Expect(err).ToNot(HaveOccurred())
Expect(logs).To(ContainSubstring("/somethingOne"))
assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs")
assert.Contains(ginkgo.GinkgoT(), logs, "/somethingOne")
})
It("disables access logging for default backend", func() {
ginkgo.It("disables access logging for default backend", func() {
f.UpdateNginxConfigMapData("enable-access-log-for-default-backend", "false")
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/somethingTwo").
Set("Host", "bar").
End()
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusNotFound))
f.HTTPTestClient().
GET("/somethingTwo").
WithHeader("Host", "bar").
Expect().
Status(http.StatusNotFound)
logs, err := f.NginxLogs()
Expect(err).ToNot(HaveOccurred())
Expect(logs).ToNot(ContainSubstring("/somethingTwo"))
assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs")
assert.NotContains(ginkgo.GinkgoT(), logs, "/somethingTwo")
})
})