Fix bug with httpjson client pointer receiver

fixes #859
This commit is contained in:
Cameron Sparr 2016-03-16 10:20:52 -06:00 committed by Michele Fadda
parent 99bfc6ba64
commit 0c4429c1bb
3 changed files with 22 additions and 12 deletions

View File

@ -1,3 +1,11 @@
## v0.11.1 [unreleased]
### Features
### Bugfixes
- [#852](https://github.com/influxdata/telegraf/issues/852): Windows zip package fix
- [#859](https://github.com/influxdata/telegraf/issues/859): httpjson plugin panic
## v0.11.0 [2016-03-15]
### Release Notes

View File

@ -55,15 +55,15 @@ type RealHTTPClient struct {
client *http.Client
}
func (c RealHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
func (c *RealHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
return c.client.Do(req)
}
func (c RealHTTPClient) SetHTTPClient(client *http.Client) {
func (c *RealHTTPClient) SetHTTPClient(client *http.Client) {
c.client = client
}
func (c RealHTTPClient) HTTPClient() *http.Client {
func (c *RealHTTPClient) HTTPClient() *http.Client {
return c.client
}
@ -289,6 +289,8 @@ func (h *HttpJson) sendRequest(serverURL string) (string, float64, error) {
func init() {
inputs.Add("httpjson", func() telegraf.Input {
return &HttpJson{client: RealHTTPClient{}}
return &HttpJson{
client: &RealHTTPClient{},
}
})
}

View File

@ -125,7 +125,7 @@ type mockHTTPClient struct {
// Mock implementation of MakeRequest. Usually returns an http.Response with
// hard-coded responseBody and statusCode. However, if the request uses a
// nonstandard method, it uses status code 405 (method not allowed)
func (c mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
func (c *mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
resp := http.Response{}
resp.StatusCode = c.statusCode
@ -147,10 +147,10 @@ func (c mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
return &resp, nil
}
func (c mockHTTPClient) SetHTTPClient(_ *http.Client) {
func (c *mockHTTPClient) SetHTTPClient(_ *http.Client) {
}
func (c mockHTTPClient) HTTPClient() *http.Client {
func (c *mockHTTPClient) HTTPClient() *http.Client {
return nil
}
@ -164,7 +164,7 @@ func (c mockHTTPClient) HTTPClient() *http.Client {
func genMockHttpJson(response string, statusCode int) []*HttpJson {
return []*HttpJson{
&HttpJson{
client: mockHTTPClient{responseBody: response, statusCode: statusCode},
client: &mockHTTPClient{responseBody: response, statusCode: statusCode},
Servers: []string{
"http://server1.example.com/metrics/",
"http://server2.example.com/metrics/",
@ -181,7 +181,7 @@ func genMockHttpJson(response string, statusCode int) []*HttpJson {
},
},
&HttpJson{
client: mockHTTPClient{responseBody: response, statusCode: statusCode},
client: &mockHTTPClient{responseBody: response, statusCode: statusCode},
Servers: []string{
"http://server3.example.com/metrics/",
"http://server4.example.com/metrics/",
@ -241,7 +241,7 @@ func TestHttpJsonGET_URL(t *testing.T) {
Servers: []string{ts.URL + "?api_key=mykey"},
Name: "",
Method: "GET",
client: RealHTTPClient{client: &http.Client{}},
client: &RealHTTPClient{client: &http.Client{}},
}
var acc testutil.Accumulator
@ -314,7 +314,7 @@ func TestHttpJsonGET(t *testing.T) {
Name: "",
Method: "GET",
Parameters: params,
client: RealHTTPClient{client: &http.Client{}},
client: &RealHTTPClient{client: &http.Client{}},
}
var acc testutil.Accumulator
@ -388,7 +388,7 @@ func TestHttpJsonPOST(t *testing.T) {
Name: "",
Method: "POST",
Parameters: params,
client: RealHTTPClient{client: &http.Client{}},
client: &RealHTTPClient{client: &http.Client{}},
}
var acc testutil.Accumulator