@@ -9,15 +9,16 @@ import (
99 "net/url"
1010 "testing"
1111
12+ "github.com/stretchr/testify/require"
13+
1214 httpconfig "github.com/influxdata/telegraf/plugins/common/http"
13- oauth "github.com/influxdata/telegraf/plugins/common/oauth"
14- plugin "github.com/influxdata/telegraf/plugins/inputs/http"
15+ "github.com/influxdata/telegraf/plugins/common/oauth"
16+ httpplugin "github.com/influxdata/telegraf/plugins/inputs/http"
1517 "github.com/influxdata/telegraf/plugins/parsers"
1618 "github.com/influxdata/telegraf/testutil"
17- "github.com/stretchr/testify/require"
1819)
1920
20- func TestHTTPwithJSONFormat (t * testing.T ) {
21+ func TestHTTPWithJSONFormat (t * testing.T ) {
2122 fakeServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2223 if r .URL .Path == "/endpoint" {
2324 _ , _ = w .Write ([]byte (simpleJSON ))
@@ -27,9 +28,9 @@ func TestHTTPwithJSONFormat(t *testing.T) {
2728 }))
2829 defer fakeServer .Close ()
2930
30- url := fakeServer .URL + "/endpoint"
31- plugin := & plugin .HTTP {
32- URLs : []string {url },
31+ address := fakeServer .URL + "/endpoint"
32+ plugin := & httpplugin .HTTP {
33+ URLs : []string {address },
3334 }
3435 metricName := "metricName"
3536
@@ -50,7 +51,7 @@ func TestHTTPwithJSONFormat(t *testing.T) {
5051 require .Equal (t , metric .Measurement , metricName )
5152 require .Len (t , acc .Metrics [0 ].Fields , 1 )
5253 require .Equal (t , acc .Metrics [0 ].Fields ["a" ], 1.2 )
53- require .Equal (t , acc .Metrics [0 ].Tags ["url" ], url )
54+ require .Equal (t , acc .Metrics [0 ].Tags ["url" ], address )
5455}
5556
5657func TestHTTPHeaders (t * testing.T ) {
@@ -69,9 +70,9 @@ func TestHTTPHeaders(t *testing.T) {
6970 }))
7071 defer fakeServer .Close ()
7172
72- url := fakeServer .URL + "/endpoint"
73- plugin := & plugin .HTTP {
74- URLs : []string {url },
73+ address := fakeServer .URL + "/endpoint"
74+ plugin := & httpplugin .HTTP {
75+ URLs : []string {address },
7576 Headers : map [string ]string {header : headerValue },
7677 }
7778
@@ -92,9 +93,9 @@ func TestInvalidStatusCode(t *testing.T) {
9293 }))
9394 defer fakeServer .Close ()
9495
95- url := fakeServer .URL + "/endpoint"
96- plugin := & plugin .HTTP {
97- URLs : []string {url },
96+ address := fakeServer .URL + "/endpoint"
97+ plugin := & httpplugin .HTTP {
98+ URLs : []string {address },
9899 }
99100
100101 metricName := "metricName"
@@ -115,9 +116,9 @@ func TestSuccessStatusCodes(t *testing.T) {
115116 }))
116117 defer fakeServer .Close ()
117118
118- url := fakeServer .URL + "/endpoint"
119- plugin := & plugin .HTTP {
120- URLs : []string {url },
119+ address := fakeServer .URL + "/endpoint"
120+ plugin := & httpplugin .HTTP {
121+ URLs : []string {address },
121122 SuccessStatusCodes : []int {200 , 202 },
122123 }
123124
@@ -143,7 +144,7 @@ func TestMethod(t *testing.T) {
143144 }))
144145 defer fakeServer .Close ()
145146
146- plugin := & plugin .HTTP {
147+ plugin := & httpplugin .HTTP {
147148 URLs : []string {fakeServer .URL },
148149 Method : "POST" ,
149150 }
@@ -169,18 +170,18 @@ func TestBodyAndContentEncoding(t *testing.T) {
169170 ts := httptest .NewServer (http .NotFoundHandler ())
170171 defer ts .Close ()
171172
172- url := fmt .Sprintf ("http://%s" , ts .Listener .Addr ().String ())
173+ address := fmt .Sprintf ("http://%s" , ts .Listener .Addr ().String ())
173174
174175 tests := []struct {
175176 name string
176- plugin * plugin .HTTP
177+ plugin * httpplugin .HTTP
177178 queryHandlerFunc func (t * testing.T , w http.ResponseWriter , r * http.Request )
178179 }{
179180 {
180181 name : "no body" ,
181- plugin : & plugin .HTTP {
182+ plugin : & httpplugin .HTTP {
182183 Method : "POST" ,
183- URLs : []string {url },
184+ URLs : []string {address },
184185 },
185186 queryHandlerFunc : func (t * testing.T , w http.ResponseWriter , r * http.Request ) {
186187 body , err := io .ReadAll (r .Body )
@@ -191,8 +192,8 @@ func TestBodyAndContentEncoding(t *testing.T) {
191192 },
192193 {
193194 name : "post body" ,
194- plugin : & plugin .HTTP {
195- URLs : []string {url },
195+ plugin : & httpplugin .HTTP {
196+ URLs : []string {address },
196197 Method : "POST" ,
197198 Body : "test" ,
198199 },
@@ -205,8 +206,8 @@ func TestBodyAndContentEncoding(t *testing.T) {
205206 },
206207 {
207208 name : "get method body is sent" ,
208- plugin : & plugin .HTTP {
209- URLs : []string {url },
209+ plugin : & httpplugin .HTTP {
210+ URLs : []string {address },
210211 Method : "GET" ,
211212 Body : "test" ,
212213 },
@@ -219,8 +220,8 @@ func TestBodyAndContentEncoding(t *testing.T) {
219220 },
220221 {
221222 name : "gzip encoding" ,
222- plugin : & plugin .HTTP {
223- URLs : []string {url },
223+ plugin : & httpplugin .HTTP {
224+ URLs : []string {address },
224225 Method : "GET" ,
225226 Body : "test" ,
226227 ContentEncoding : "gzip" ,
@@ -269,13 +270,13 @@ func TestOAuthClientCredentialsGrant(t *testing.T) {
269270
270271 tests := []struct {
271272 name string
272- plugin * plugin .HTTP
273+ plugin * httpplugin .HTTP
273274 tokenHandler TestHandlerFunc
274275 handler TestHandlerFunc
275276 }{
276277 {
277278 name : "no credentials" ,
278- plugin : & plugin .HTTP {
279+ plugin : & httpplugin .HTTP {
279280 URLs : []string {u .String ()},
280281 },
281282 handler : func (t * testing.T , w http.ResponseWriter , r * http.Request ) {
@@ -285,7 +286,7 @@ func TestOAuthClientCredentialsGrant(t *testing.T) {
285286 },
286287 {
287288 name : "success" ,
288- plugin : & plugin .HTTP {
289+ plugin : & httpplugin .HTTP {
289290 URLs : []string {u .String () + "/write" },
290291 HTTPClientConfig : httpconfig.HTTPClientConfig {
291292 OAuth2Config : oauth.OAuth2Config {
0 commit comments