@@ -32,9 +32,9 @@ func TestFailIfSelfSignedCA(t *testing.T) {
3232 }))
3333 defer target .Close ()
3434
35- req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL , nil )
35+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?module=default& target=" + target .URL , nil )
3636 recorder := httptest .NewRecorder ()
37- probeHandler (recorder , req , log .NewNopLogger (), config.Config {})
37+ probeHandler (recorder , req , log .NewNopLogger (), config.Config {Modules : map [ string ]config. Module { "default" : {}} })
3838
3939 resp := recorder .Result ()
4040 body , _ := ioutil .ReadAll (resp .Body )
@@ -45,13 +45,21 @@ func TestFailIfSelfSignedCA(t *testing.T) {
4545}
4646
4747func TestSucceedIfSelfSignedCA (t * testing.T ) {
48- c := config.Config {}
49- c .HTTPClientConfig .TLSConfig .InsecureSkipVerify = true
48+ c := config.Config {
49+ Modules : map [string ]config.Module {
50+ "default" : {
51+ HTTPClientConfig : pconfig.HTTPClientConfig {
52+ TLSConfig : pconfig.TLSConfig {
53+ InsecureSkipVerify : true ,
54+ },
55+ },
56+ }},
57+ }
5058 target := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
5159 }))
5260 defer target .Close ()
5361
54- req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL , nil )
62+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?module=default& target=" + target .URL , nil )
5563 recorder := httptest .NewRecorder ()
5664 probeHandler (recorder , req , log .NewNopLogger (), c )
5765
@@ -63,6 +71,29 @@ func TestSucceedIfSelfSignedCA(t *testing.T) {
6371 }
6472}
6573
74+ func TestDefaultModule (t * testing.T ) {
75+ target := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
76+ }))
77+ defer target .Close ()
78+
79+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL , nil )
80+ recorder := httptest .NewRecorder ()
81+ probeHandler (recorder , req , log .NewNopLogger (), config.Config {Modules : map [string ]config.Module {"default" : {}}})
82+
83+ resp := recorder .Result ()
84+ if resp .StatusCode != http .StatusOK {
85+ t .Fatalf ("Default module test fails unexpectedly, expected 200, got %d" , resp .StatusCode )
86+ }
87+
88+ // Module doesn't exist.
89+ recorder = httptest .NewRecorder ()
90+ probeHandler (recorder , req , log .NewNopLogger (), config.Config {Modules : map [string ]config.Module {"foo" : {}}})
91+ resp = recorder .Result ()
92+ if resp .StatusCode != http .StatusBadRequest {
93+ t .Fatalf ("Default module test fails unexpectedly, expected 400, got %d" , resp .StatusCode )
94+ }
95+ }
96+
6697func TestFailIfTargetMissing (t * testing.T ) {
6798 req := httptest .NewRequest ("GET" , "http://example.com/foo" , nil )
6899 recorder := httptest .NewRecorder ()
@@ -86,9 +117,9 @@ func TestDefaultAcceptHeader(t *testing.T) {
86117 }))
87118 defer target .Close ()
88119
89- req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL , nil )
120+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?module=default& target=" + target .URL , nil )
90121 recorder := httptest .NewRecorder ()
91- probeHandler (recorder , req , log .NewNopLogger (), config.Config {})
122+ probeHandler (recorder , req , log .NewNopLogger (), config.Config {Modules : map [ string ]config. Module { "default" : {}} })
92123
93124 resp := recorder .Result ()
94125 body , _ := ioutil .ReadAll (resp .Body )
@@ -118,7 +149,7 @@ func TestCorrectResponse(t *testing.T) {
118149 t .Fatalf ("Failed to load config file %s" , test .ConfigFile )
119150 }
120151
121- req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL + test .ServeFile , nil )
152+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?module=default& target=" + target .URL + test .ServeFile , nil )
122153 recorder := httptest .NewRecorder ()
123154 probeHandler (recorder , req , log .NewNopLogger (), c )
124155
@@ -145,15 +176,21 @@ func TestBasicAuth(t *testing.T) {
145176 }))
146177 defer target .Close ()
147178
148- req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL , nil )
179+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?module=default& target=" + target .URL , nil )
149180 recorder := httptest .NewRecorder ()
150- c := config.Config {}
151- auth := & pconfig.BasicAuth {
152- Username : username ,
153- Password : pconfig .Secret (password ),
181+ c := config.Config {
182+ Modules : map [string ]config.Module {
183+ "default" : {
184+ HTTPClientConfig : pconfig.HTTPClientConfig {
185+ BasicAuth : & pconfig.BasicAuth {
186+ Username : username ,
187+ Password : pconfig .Secret (password ),
188+ },
189+ },
190+ },
191+ },
154192 }
155193
156- c .HTTPClientConfig .BasicAuth = auth
157194 probeHandler (recorder , req , log .NewNopLogger (), c )
158195
159196 resp := recorder .Result ()
@@ -175,11 +212,16 @@ func TestBearerToken(t *testing.T) {
175212 }))
176213 defer target .Close ()
177214
178- req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL , nil )
215+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?module=default& target=" + target .URL , nil )
179216 recorder := httptest .NewRecorder ()
180- c := config.Config {}
217+ c := config.Config {
218+ Modules : map [string ]config.Module {"default" : {
219+ HTTPClientConfig : pconfig.HTTPClientConfig {
220+ BearerToken : pconfig .Secret (token ),
221+ },
222+ }},
223+ }
181224
182- c .HTTPClientConfig .BearerToken = pconfig .Secret (token )
183225 probeHandler (recorder , req , log .NewNopLogger (), c )
184226
185227 resp := recorder .Result ()
@@ -206,10 +248,15 @@ func TestHTTPHeaders(t *testing.T) {
206248 }))
207249 defer target .Close ()
208250
209- req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?target=" + target .URL , nil )
251+ req := httptest .NewRequest ("GET" , "http://example.com/foo" + "?module=default& target=" + target .URL , nil )
210252 recorder := httptest .NewRecorder ()
211- c := config.Config {}
212- c .Headers = headers
253+ c := config.Config {
254+ Modules : map [string ]config.Module {
255+ "default" : {
256+ Headers : headers ,
257+ },
258+ },
259+ }
213260
214261 probeHandler (recorder , req , log .NewNopLogger (), c )
215262
@@ -264,9 +311,15 @@ func TestBodyPostTemplate(t *testing.T) {
264311 w .WriteHeader (http .StatusOK )
265312 }))
266313
267- req := httptest .NewRequest ("POST" , "http://example.com/foo" + "?target=" + target .URL , strings .NewReader (test .Body .Content ))
314+ req := httptest .NewRequest ("POST" , "http://example.com/foo" + "?module=default& target=" + target .URL , strings .NewReader (test .Body .Content ))
268315 recorder := httptest .NewRecorder ()
269- c := config.Config {Body : test .Body }
316+ c := config.Config {
317+ Modules : map [string ]config.Module {
318+ "default" : {
319+ Body : test .Body ,
320+ },
321+ },
322+ }
270323
271324 probeHandler (recorder , req , log .NewNopLogger (), c )
272325
@@ -351,15 +404,21 @@ func TestBodyPostQuery(t *testing.T) {
351404 w .WriteHeader (http .StatusOK )
352405 }))
353406
354- req := httptest .NewRequest ("POST" , "http://example.com/foo" + "?target=" + target .URL , strings .NewReader (test .Body .Content ))
407+ req := httptest .NewRequest ("POST" , "http://example.com/foo" + "?module=default& target=" + target .URL , strings .NewReader (test .Body .Content ))
355408 q := req .URL .Query ()
356409 for k , v := range test .QueryParams {
357410 q .Add (k , v )
358411 }
359412 req .URL .RawQuery = q .Encode ()
360413
361414 recorder := httptest .NewRecorder ()
362- c := config.Config {Body : test .Body }
415+ c := config.Config {
416+ Modules : map [string ]config.Module {
417+ "default" : {
418+ Body : test .Body ,
419+ },
420+ },
421+ }
363422
364423 probeHandler (recorder , req , log .NewNopLogger (), c )
365424
0 commit comments