@@ -319,3 +319,41 @@ func (*requestsSuite) TestDoRequestWithInferrableContentLength(c *gc.C) {
319
319
// calls. Failures are already massively tested in practice. DoRequest and
320
320
// AssertJSONResponse are also indirectly tested as they are called by
321
321
// AssertJSONCall.
322
+
323
+ type urlRewritingTransportSuite struct {
324
+ server * httptest.Server
325
+ }
326
+
327
+ var _ = gc .Suite (& urlRewritingTransportSuite {})
328
+
329
+ func (s * urlRewritingTransportSuite ) SetUpTest (c * gc.C ) {
330
+ s .server = httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
331
+ w .Write ([]byte (r .URL .String ()))
332
+ }))
333
+ }
334
+
335
+ func (s * urlRewritingTransportSuite ) TestTransport (c * gc.C ) {
336
+ t := httptesting.URLRewritingTransport {
337
+ MatchPrefix : "http://example.com" ,
338
+ Replace : s .server .URL ,
339
+ }
340
+ client := http.Client {
341
+ Transport : & t ,
342
+ }
343
+ resp , err := client .Get ("http://example.com/path" )
344
+ c .Assert (err , jc .ErrorIsNil )
345
+ body , err := ioutil .ReadAll (resp .Body )
346
+ c .Assert (err , jc .ErrorIsNil )
347
+ resp .Body .Close ()
348
+ c .Assert (resp .Request .URL .String (), gc .Equals , "http://example.com/path" )
349
+ c .Assert (string (body ), gc .Equals , "/path" )
350
+
351
+ t .RoundTripper = & http.Transport {}
352
+ resp , err = client .Get (s .server .URL + "/otherpath" )
353
+ c .Assert (err , jc .ErrorIsNil )
354
+ body , err = ioutil .ReadAll (resp .Body )
355
+ c .Assert (err , jc .ErrorIsNil )
356
+ resp .Body .Close ()
357
+ c .Assert (resp .Request .URL .String (), gc .Equals , s .server .URL + "/otherpath" )
358
+ c .Assert (string (body ), gc .Equals , "/otherpath" )
359
+ }
0 commit comments