Fix bad http GET parameter encoding, add unit test

This commit is contained in:
Cameron Sparr 2016-02-23 10:07:56 -07:00
parent 918c3fb260
commit 69e4f16b13
2 changed files with 13 additions and 5 deletions

View File

@ -188,10 +188,10 @@ func (h *HttpJson) sendRequest(serverURL string) (string, float64, error) {
switch {
case h.Method == "GET":
requestURL.RawQuery = params.Encode()
for k, v := range h.Parameters {
params.Add(k, v)
}
requestURL.RawQuery = params.Encode()
case h.Method == "POST":
requestURL.RawQuery = ""

View File

@ -222,7 +222,14 @@ func TestHttpJson200(t *testing.T) {
// Test litecoin sample output
func TestHttpJsonLiteCoin(t *testing.T) {
params := map[string]string{
"api_key": "mykey",
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
assert.NoError(t, err)
key := r.Form.Get("api_key")
assert.Equal(t, "mykey", key)
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, validJSON2)
}))
@ -232,6 +239,7 @@ func TestHttpJsonLiteCoin(t *testing.T) {
Servers: []string{ts.URL},
Name: "",
Method: "GET",
Parameters: params,
client: RealHTTPClient{client: &http.Client{}},
}