Fix bad http GET parameter encoding, add unit test

This commit is contained in:
Cameron Sparr 2016-02-23 10:07:56 -07:00 committed by Michele Fadda
parent 5a54f0aa16
commit 4ea2085c33
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 { switch {
case h.Method == "GET": case h.Method == "GET":
requestURL.RawQuery = params.Encode()
for k, v := range h.Parameters { for k, v := range h.Parameters {
params.Add(k, v) params.Add(k, v)
} }
requestURL.RawQuery = params.Encode()
case h.Method == "POST": case h.Method == "POST":
requestURL.RawQuery = "" requestURL.RawQuery = ""

View File

@ -222,17 +222,25 @@ func TestHttpJson200(t *testing.T) {
// Test litecoin sample output // Test litecoin sample output
func TestHttpJsonLiteCoin(t *testing.T) { func TestHttpJsonLiteCoin(t *testing.T) {
params := map[string]string{
"api_key": "mykey",
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 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) w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, validJSON2) fmt.Fprintln(w, validJSON2)
})) }))
defer ts.Close() defer ts.Close()
a := HttpJson{ a := HttpJson{
Servers: []string{ts.URL}, Servers: []string{ts.URL},
Name: "", Name: "",
Method: "GET", Method: "GET",
client: RealHTTPClient{client: &http.Client{}}, Parameters: params,
client: RealHTTPClient{client: &http.Client{}},
} }
var acc testutil.Accumulator var acc testutil.Accumulator