Fix bad http GET parameter encoding, add unit test
This commit is contained in:
		
							parent
							
								
									918c3fb260
								
							
						
					
					
						commit
						69e4f16b13
					
				|  | @ -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 = "" | ||||
|  |  | |||
|  | @ -222,17 +222,25 @@ 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) | ||||
| 	})) | ||||
| 	defer ts.Close() | ||||
| 
 | ||||
| 	a := HttpJson{ | ||||
| 		Servers: []string{ts.URL}, | ||||
| 		Name:    "", | ||||
| 		Method:  "GET", | ||||
| 		client:  RealHTTPClient{client: &http.Client{}}, | ||||
| 		Servers:    []string{ts.URL}, | ||||
| 		Name:       "", | ||||
| 		Method:     "GET", | ||||
| 		Parameters: params, | ||||
| 		client:     RealHTTPClient{client: &http.Client{}}, | ||||
| 	} | ||||
| 
 | ||||
| 	var acc testutil.Accumulator | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue