Skip to content

Commit

Permalink
Adding url.Values to request RawQuery, fixes 522
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinesh Kumar authored and ernesto-jimenez committed Mar 18, 2018
1 parent b89eecf commit 6efb0c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion assert/http_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
// an error if building a new request fails.
func httpCode(handler http.HandlerFunc, method, url string, values url.Values) (int, error) {
w := httptest.NewRecorder()
req, err := http.NewRequest(method, url+"?"+values.Encode(), nil)
req, err := http.NewRequest(method, url, nil)
if err != nil {
return -1, err
}
req.URL.RawQuery = values.Encode()
handler(w, req)
return w.Code, nil
}
Expand Down
29 changes: 29 additions & 0 deletions assert/http_assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@ func httpHelloName(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf("Hello, %s!", name)))
}

func TestHTTPRequestWithNoParams(t *testing.T) {
var got *http.Request
handler := func(w http.ResponseWriter, r *http.Request) {
got = r
w.WriteHeader(http.StatusOK)
}

True(t, HTTPSuccess(t, handler, "GET", "/url", nil))

Empty(t, got.URL.Query())
Equal(t, "/url", got.URL.RequestURI())
}

func TestHTTPRequestWithParams(t *testing.T) {
var got *http.Request
handler := func(w http.ResponseWriter, r *http.Request) {
got = r
w.WriteHeader(http.StatusOK)
}
params := url.Values{}
params.Add("id", "12345")

True(t, HTTPSuccess(t, handler, "GET", "/url", params))

Equal(t, url.Values{"id": []string{"12345"}}, got.URL.Query())
Equal(t, "/url?id=12345", got.URL.String())
Equal(t, "/url?id=12345", got.URL.RequestURI())
}

func TestHttpBody(t *testing.T) {
assert := New(t)
mockT := new(testing.T)
Expand Down

0 comments on commit 6efb0c4

Please sign in to comment.