Added additional http response helpers.
This commit is contained in:
parent
a5d8d2ea35
commit
58c72c0705
1 changed files with 18 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -38,7 +39,12 @@ type httpResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpResponse) assertStatusCode(code int) *httpResponse {
|
func (h *httpResponse) assertStatusCode(code int) *httpResponse {
|
||||||
assert.Equal(h.t, code, h.Response)
|
assert.Equal(h.t, code, h.Response.StatusCode)
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *httpResponse) assertRedirect(t *testing.T, destination string) *httpResponse {
|
||||||
|
assert.Equal(t, destination, h.Header.Get("Location"))
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,3 +66,14 @@ func getRequest(t *testing.T, route string, routeParams ...interface{}) *httpRes
|
||||||
}
|
}
|
||||||
return &h
|
return &h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func postRequest(t *testing.T, values url.Values, route string, routeParams ...interface{}) *httpResponse {
|
||||||
|
cli := http.Client{}
|
||||||
|
resp, err := cli.PostForm(srv.URL+c.Web.Reverse(route, routeParams), values)
|
||||||
|
require.NoError(t, err)
|
||||||
|
h := httpResponse{
|
||||||
|
t: t,
|
||||||
|
Response: resp,
|
||||||
|
}
|
||||||
|
return &h
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue