enhance test logic

This commit is contained in:
Anish Ramasekar 2018-10-26 11:21:44 -05:00
parent 4393f8cd9e
commit d3a82f7b04
No known key found for this signature in database
GPG key ID: 649FAC6DAB39EA54
2 changed files with 10 additions and 15 deletions

View file

@ -17,7 +17,6 @@ limitations under the License.
package annotations package annotations
import ( import (
"fmt"
"net/http" "net/http"
"time" "time"
@ -58,18 +57,15 @@ var _ = framework.IngressNginxDescribe("Annotations - Forcesslredirect", func()
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
_, _, errs := gorequest.New(). resp, _, errs := gorequest.New().
Get(f.IngressController.HTTPURL). Get(f.IngressController.HTTPURL).
Retry(10, 1*time.Second, http.StatusNotFound). Retry(10, 1*time.Second, http.StatusNotFound).
RedirectPolicy(noRedirectPolicyFunc).
Set("Host", host). Set("Host", host).
End() End()
Expect(errs[0].Error()).Should(ContainSubstring(`https://forcesslredirect.bar.com/`)) Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect))
log, err := f.NginxLogs() Expect(resp.Header.Get("Location")).Should(Equal("https://forcesslredirect.bar.com/"))
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"`)))
}) })
}) })

View file

@ -61,16 +61,15 @@ var _ = framework.IngressNginxDescribe("Annotations - Fromtowwwredirect", func()
By("sending request to www.fromtowwwredirect.bar.com") By("sending request to www.fromtowwwredirect.bar.com")
gorequest.New(). resp, _, errs := gorequest.New().
Get(fmt.Sprintf("%s/%s", f.IngressController.HTTPURL, "foo")). Get(fmt.Sprintf("%s/%s", f.IngressController.HTTPURL, "foo")).
Retry(10, 1*time.Second, http.StatusNotFound). Retry(10, 1*time.Second, http.StatusNotFound).
RedirectPolicy(noRedirectPolicyFunc).
Set("Host", fmt.Sprintf("%s.%s", "www", host)). Set("Host", fmt.Sprintf("%s.%s", "www", host)).
End() End()
log, err := f.NginxLogs() Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(err).ToNot(HaveOccurred()) Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect))
Expect(log).ToNot(BeEmpty()) Expect(resp.Header.Get("Location")).Should(Equal("http://fromtowwwredirect.bar.com/foo"))
Expect(log).To(ContainSubstring(fmt.Sprintf(` "GET /foo HTTP/1.1" 308 171 "-" "Go-http-client/1.1"`)))
}) })
}) })