iris
iris copied to clipboard
How to disable auto redirect in httptest?
I have api router need ctx.Redirect(targetURL, statusCode), I want to check the targetURL is ok,
app.get("/a", func(ctx iris.Context){
ctx.Redirect("https://google.com", 302)
})
i write test like :
func TestCreate(t *testing.T) {
t.Run("301 check", func(t *testing.T) {
e := httptest.New(t, TestServer)
tt := e.GET("/a").
response := tt.Expect()
response.Status(301)
fmt.Println(response.Header("Location").Raw())
})
}
the http request will request google.com but it's not my expect result, i just want to get 301 and the text in http header location
how to disable request auto redirect and let test pass?
in httptest.go line 103change to
testConfiguration := httpexpect.Config{
BaseURL: conf.URL,
Client: &http.Client{
Transport: httpexpect.NewBinder(app),
Jar: httpexpect.NewJar(),
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
},
Reporter: httpexpect.NewAssertReporter(t),
}
httptest api can provide params to disable autoredirct?