Refactor e2e tests to use testify y httpexpect
This commit is contained in:
parent
046e2d959d
commit
f9624cbe46
80 changed files with 2280 additions and 2631 deletions
|
|
@ -22,8 +22,8 @@ import (
|
|||
"net"
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
|
@ -33,12 +33,12 @@ var _ = framework.DescribeSetting("use-proxy-protocol", func() {
|
|||
|
||||
setting := "use-proxy-protocol"
|
||||
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeployment()
|
||||
f.UpdateNginxConfigMapData(setting, "false")
|
||||
})
|
||||
|
||||
It("should respect port passed by the PROXY Protocol", func() {
|
||||
ginkgo.It("should respect port passed by the PROXY Protocol", func() {
|
||||
host := "proxy-protocol"
|
||||
|
||||
f.UpdateNginxConfigMapData(setting, "true")
|
||||
|
|
@ -54,7 +54,7 @@ var _ = framework.DescribeSetting("use-proxy-protocol", func() {
|
|||
ip := f.GetNginxIP()
|
||||
|
||||
conn, err := net.Dial("tcp", net.JoinHostPort(ip, "80"))
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error creating connection to %s:80", ip)
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error creating connection to %s:80", ip)
|
||||
defer conn.Close()
|
||||
|
||||
header := "PROXY TCP4 192.168.0.1 192.168.0.11 56324 1234\r\n"
|
||||
|
|
@ -62,15 +62,16 @@ var _ = framework.DescribeSetting("use-proxy-protocol", func() {
|
|||
conn.Write([]byte("GET / HTTP/1.1\r\nHost: proxy-protocol\r\n\r\n"))
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error reading connection data")
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error reading connection data")
|
||||
|
||||
body := string(data)
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", "proxy-protocol")))
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=1234")))
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-proto=http")))
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-for=192.168.0.1")))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("host=%v", "proxy-protocol"))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("x-forwarded-port=1234"))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("x-forwarded-proto=http"))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("x-forwarded-for=192.168.0.1"))
|
||||
})
|
||||
|
||||
It("should respect proto passed by the PROXY Protocol server port", func() {
|
||||
ginkgo.It("should respect proto passed by the PROXY Protocol server port", func() {
|
||||
host := "proxy-protocol"
|
||||
|
||||
f.UpdateNginxConfigMapData(setting, "true")
|
||||
|
|
@ -86,7 +87,7 @@ var _ = framework.DescribeSetting("use-proxy-protocol", func() {
|
|||
ip := f.GetNginxIP()
|
||||
|
||||
conn, err := net.Dial("tcp", net.JoinHostPort(ip, "80"))
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error creating connection to %s:80", ip)
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error creating connection to %s:80", ip)
|
||||
defer conn.Close()
|
||||
|
||||
header := "PROXY TCP4 192.168.0.1 192.168.0.11 56324 443\r\n"
|
||||
|
|
@ -94,11 +95,12 @@ var _ = framework.DescribeSetting("use-proxy-protocol", func() {
|
|||
conn.Write([]byte("GET / HTTP/1.1\r\nHost: proxy-protocol\r\n\r\n"))
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
Expect(err).NotTo(HaveOccurred(), "unexpected error reading connection data")
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error reading connection data")
|
||||
|
||||
body := string(data)
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", "proxy-protocol")))
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=443")))
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-proto=https")))
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-for=192.168.0.1")))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("host=%v", "proxy-protocol"))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("x-forwarded-port=443"))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("x-forwarded-proto=https"))
|
||||
assert.Contains(ginkgo.GinkgoT(), body, fmt.Sprintf("x-forwarded-for=192.168.0.1"))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue