From d3a82f7b04d97780b38104413dddf4d989035c53 Mon Sep 17 00:00:00 2001 From: Anish Ramasekar Date: Fri, 26 Oct 2018 11:21:44 -0500 Subject: [PATCH] enhance test logic --- test/e2e/annotations/forcesslredirect.go | 14 +++++--------- test/e2e/annotations/fromtowwwredirect.go | 11 +++++------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/test/e2e/annotations/forcesslredirect.go b/test/e2e/annotations/forcesslredirect.go index 7b542b286..dd3f963fe 100644 --- a/test/e2e/annotations/forcesslredirect.go +++ b/test/e2e/annotations/forcesslredirect.go @@ -17,7 +17,6 @@ limitations under the License. package annotations import ( - "fmt" "net/http" "time" @@ -58,18 +57,15 @@ var _ = framework.IngressNginxDescribe("Annotations - Forcesslredirect", func() }) Expect(err).NotTo(HaveOccurred()) - _, _, errs := gorequest.New(). + resp, _, errs := gorequest.New(). Get(f.IngressController.HTTPURL). Retry(10, 1*time.Second, http.StatusNotFound). + RedirectPolicy(noRedirectPolicyFunc). Set("Host", host). End() - Expect(errs[0].Error()).Should(ContainSubstring(`https://forcesslredirect.bar.com/`)) - - log, err := f.NginxLogs() - Expect(err).ToNot(HaveOccurred()) - Expect(log).ToNot(BeEmpty()) - - Expect(log).To(ContainSubstring(fmt.Sprintf(` "GET / HTTP/1.1" 308 171 "-" "Go-http-client/1.1"`))) + Expect(len(errs)).Should(BeNumerically("==", 0)) + Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect)) + Expect(resp.Header.Get("Location")).Should(Equal("https://forcesslredirect.bar.com/")) }) }) diff --git a/test/e2e/annotations/fromtowwwredirect.go b/test/e2e/annotations/fromtowwwredirect.go index 7ae32e36f..b5b292577 100644 --- a/test/e2e/annotations/fromtowwwredirect.go +++ b/test/e2e/annotations/fromtowwwredirect.go @@ -61,16 +61,15 @@ var _ = framework.IngressNginxDescribe("Annotations - Fromtowwwredirect", func() By("sending request to www.fromtowwwredirect.bar.com") - gorequest.New(). + resp, _, errs := gorequest.New(). Get(fmt.Sprintf("%s/%s", f.IngressController.HTTPURL, "foo")). Retry(10, 1*time.Second, http.StatusNotFound). + RedirectPolicy(noRedirectPolicyFunc). Set("Host", fmt.Sprintf("%s.%s", "www", host)). End() - log, err := f.NginxLogs() - Expect(err).ToNot(HaveOccurred()) - Expect(log).ToNot(BeEmpty()) - - Expect(log).To(ContainSubstring(fmt.Sprintf(` "GET /foo HTTP/1.1" 308 171 "-" "Go-http-client/1.1"`))) + Expect(len(errs)).Should(BeNumerically("==", 0)) + Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect)) + Expect(resp.Header.Get("Location")).Should(Equal("http://fromtowwwredirect.bar.com/foo")) }) })