http.Redirect(w, r, "/", http.StatusSeeOther)
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)server := httptest.NewServer(handler)
defer server.Close()
data := url.Values{
"login": {"john"},
"password": {"secret"},
}
req, err := http.NewRequest("POST", server.URL, strings.NewReader(data.Encode()))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
transport := http.Transport{}
res, err := transport.RoundTrip(req)
if err != nil {
panic(err)
}I'm trying to test my http handler where I redirect after a successful post request (i.e. user logs in). Check out- demo repo https://github.com/zemirco/redirect- and error message https://travis-ci.org/zemirco/redirect#L119The first test is fine. The second test fails.
Do you have an example test? Independently from HTTP as you wrote.