@@ -18,15 +18,17 @@ import (
1818
1919var _ = Describe ("HTTPClient" , func () {
2020 var (
21- httpClient * HTTPClient
22- server * ghttp.Server
23- logger loggerfakes.FakeLogger
21+ httpClient * HTTPClient
22+ fastErroringHttpClient * HTTPClient
23+ server * ghttp.Server
24+ logger loggerfakes.FakeLogger
25+ opts Opts
2426 )
2527
26- BeforeEach (func () {
28+ JustBeforeEach (func () {
2729 logger = loggerfakes.FakeLogger {}
2830
29- httpClient = NewHTTPClient (& http.Client {
31+ httpClient = NewHTTPClientOpts (& http.Client {
3032 Transport : & http.Transport {
3133 TLSClientConfig : & tls.Config {
3234 RootCAs : nil ,
@@ -36,14 +38,33 @@ var _ = Describe("HTTPClient", func() {
3638 Proxy : http .ProxyFromEnvironment ,
3739
3840 Dial : (& net.Dialer {
39- Timeout : 10 * time .Millisecond ,
41+ Timeout : 10 * time .Second ,
4042 KeepAlive : 0 ,
4143 }).Dial ,
4244
43- TLSHandshakeTimeout : 10 * time .Millisecond ,
45+ TLSHandshakeTimeout : 10 * time .Second ,
4446 DisableKeepAlives : true ,
4547 },
46- }, & logger )
48+ }, & logger , opts )
49+
50+ fastErroringHttpClient = NewHTTPClientOpts (& http.Client {
51+ Transport : & http.Transport {
52+ TLSClientConfig : & tls.Config {
53+ RootCAs : nil ,
54+ InsecureSkipVerify : true ,
55+ },
56+
57+ Proxy : http .ProxyFromEnvironment ,
58+
59+ Dial : (& net.Dialer {
60+ Timeout : 1 * time .Millisecond ,
61+ KeepAlive : 0 ,
62+ }).Dial ,
63+
64+ TLSHandshakeTimeout : 1 * time .Millisecond ,
65+ DisableKeepAlives : true ,
66+ },
67+ }, & logger , opts )
4768
4869 server = ghttp .NewServer ()
4970 })
@@ -115,46 +136,23 @@ var _ = Describe("HTTPClient", func() {
115136 It ("redacts passwords from error message" , func () {
116137 url := "http://foo:bar@10.10.0.0/path"
117138
118- _ , err := httpClient .PostCustomized (url , []byte ("post-request" ), func (r * http.Request ) {})
139+ _ , err := fastErroringHttpClient .PostCustomized (url , []byte ("post-request" ), func (r * http.Request ) {})
119140 Expect (err ).To (HaveOccurred ())
120141 Expect (err .Error ()).To (ContainSubstring ("http://foo:<redacted>@10.10.0.0/path" ))
121142 })
122143
123144 It ("redacts passwords from error message for https calls" , func () {
124145 url := "https://foo:bar@10.10.0.0/path"
125146
126- _ , err := httpClient .PostCustomized (url , []byte ("post-request" ), func (r * http.Request ) {})
147+ _ , err := fastErroringHttpClient .PostCustomized (url , []byte ("post-request" ), func (r * http.Request ) {})
127148 Expect (err ).To (HaveOccurred ())
128149 Expect (err .Error ()).To (ContainSubstring ("https://foo:<redacted>@10.10.0.0/path" ))
129150 })
130151
131152 Describe ("httpclient opts" , func () {
132- var opts Opts
133153
134154 BeforeEach (func () {
135155 opts = Opts {NoRedactUrlQuery : true }
136-
137- httpClient = NewHTTPClientOpts (& http.Client {
138- Transport : & http.Transport {
139- TLSClientConfig : & tls.Config {
140- RootCAs : nil ,
141- InsecureSkipVerify : true ,
142- },
143-
144- Proxy : http .ProxyFromEnvironment ,
145-
146- Dial : (& net.Dialer {
147- Timeout : 10 * time .Millisecond ,
148- KeepAlive : 0 ,
149- }).Dial ,
150-
151- TLSHandshakeTimeout : 10 * time .Millisecond ,
152- DisableKeepAlives : true ,
153- },
154- },
155- & logger ,
156- opts ,
157- )
158156 })
159157
160158 It ("does not redact every query param from endpoint for https calls" , func () {
@@ -170,28 +168,6 @@ var _ = Describe("HTTPClient", func() {
170168 Context ("httpclient has been configured to redact query parmas" , func () {
171169 BeforeEach (func () {
172170 opts = Opts {}
173-
174- httpClient = NewHTTPClientOpts (& http.Client {
175- Transport : & http.Transport {
176- TLSClientConfig : & tls.Config {
177- RootCAs : nil ,
178- InsecureSkipVerify : true ,
179- },
180-
181- Proxy : http .ProxyFromEnvironment ,
182-
183- Dial : (& net.Dialer {
184- Timeout : 10 * time .Millisecond ,
185- KeepAlive : 0 ,
186- }).Dial ,
187-
188- TLSHandshakeTimeout : 10 * time .Millisecond ,
189- DisableKeepAlives : true ,
190- },
191- },
192- & logger ,
193- opts ,
194- )
195171 })
196172
197173 It ("redacts every query param from endpoint for https calls" , func () {
@@ -234,32 +210,8 @@ var _ = Describe("HTTPClient", func() {
234210 })
235211
236212 Describe ("httpclient opts" , func () {
237- var opts Opts
238-
239213 BeforeEach (func () {
240214 opts = Opts {NoRedactUrlQuery : true }
241-
242- httpClient = NewHTTPClientOpts (& http.Client {
243- Transport : & http.Transport {
244- TLSClientConfig : & tls.Config {
245- RootCAs : nil ,
246- InsecureSkipVerify : true ,
247- },
248-
249- Proxy : http .ProxyFromEnvironment ,
250-
251- Dial : (& net.Dialer {
252- Timeout : 10 * time .Millisecond ,
253- KeepAlive : 0 ,
254- }).Dial ,
255-
256- TLSHandshakeTimeout : 10 * time .Millisecond ,
257- DisableKeepAlives : true ,
258- },
259- },
260- & logger ,
261- opts ,
262- )
263215 })
264216
265217 It ("does not redact every query param from endpoint for https calls" , func () {
@@ -274,28 +226,6 @@ var _ = Describe("HTTPClient", func() {
274226 Context ("httpclient has been configured to redact query parmas" , func () {
275227 BeforeEach (func () {
276228 opts = Opts {}
277-
278- httpClient = NewHTTPClientOpts (& http.Client {
279- Transport : & http.Transport {
280- TLSClientConfig : & tls.Config {
281- RootCAs : nil ,
282- InsecureSkipVerify : true ,
283- },
284-
285- Proxy : http .ProxyFromEnvironment ,
286-
287- Dial : (& net.Dialer {
288- Timeout : 10 * time .Millisecond ,
289- KeepAlive : 0 ,
290- }).Dial ,
291-
292- TLSHandshakeTimeout : 10 * time .Millisecond ,
293- DisableKeepAlives : true ,
294- },
295- },
296- & logger ,
297- opts ,
298- )
299229 })
300230
301231 It ("redacts every query param from endpoint for https calls" , func () {
@@ -375,46 +305,22 @@ var _ = Describe("HTTPClient", func() {
375305 It ("redacts passwords from error message" , func () {
376306 url := "http://foo:bar@10.10.0.0/path"
377307
378- _ , err := httpClient .PutCustomized (url , []byte ("put-request" ), func (r * http.Request ) {})
308+ _ , err := fastErroringHttpClient .PutCustomized (url , []byte ("put-request" ), func (r * http.Request ) {})
379309 Expect (err ).To (HaveOccurred ())
380310 Expect (err .Error ()).To (ContainSubstring ("http://foo:<redacted>@10.10.0.0/path" ))
381311 })
382312
383313 It ("redacts passwords from error message for https calls" , func () {
384314 url := "https://foo:bar@10.10.0.0/path"
385315
386- _ , err := httpClient .PutCustomized (url , []byte ("put-request" ), func (r * http.Request ) {})
316+ _ , err := fastErroringHttpClient .PutCustomized (url , []byte ("put-request" ), func (r * http.Request ) {})
387317 Expect (err ).To (HaveOccurred ())
388318 Expect (err .Error ()).To (ContainSubstring ("https://foo:<redacted>@10.10.0.0/path" ))
389319 })
390320
391321 Describe ("httpclient opts" , func () {
392- var opts Opts
393-
394322 BeforeEach (func () {
395323 opts = Opts {NoRedactUrlQuery : true }
396-
397- httpClient = NewHTTPClientOpts (& http.Client {
398- Transport : & http.Transport {
399- TLSClientConfig : & tls.Config {
400- RootCAs : nil ,
401- InsecureSkipVerify : true ,
402- },
403-
404- Proxy : http .ProxyFromEnvironment ,
405-
406- Dial : (& net.Dialer {
407- Timeout : 10 * time .Millisecond ,
408- KeepAlive : 0 ,
409- }).Dial ,
410-
411- TLSHandshakeTimeout : 10 * time .Millisecond ,
412- DisableKeepAlives : true ,
413- },
414- },
415- & logger ,
416- opts ,
417- )
418324 })
419325
420326 It ("does not redact every query param from endpoint for https calls" , func () {
@@ -429,28 +335,6 @@ var _ = Describe("HTTPClient", func() {
429335 Context ("httpclient has been configured to redact query parmas" , func () {
430336 BeforeEach (func () {
431337 opts = Opts {}
432-
433- httpClient = NewHTTPClientOpts (& http.Client {
434- Transport : & http.Transport {
435- TLSClientConfig : & tls.Config {
436- RootCAs : nil ,
437- InsecureSkipVerify : true ,
438- },
439-
440- Proxy : http .ProxyFromEnvironment ,
441-
442- Dial : (& net.Dialer {
443- Timeout : 10 * time .Millisecond ,
444- KeepAlive : 0 ,
445- }).Dial ,
446-
447- TLSHandshakeTimeout : 10 * time .Millisecond ,
448- DisableKeepAlives : true ,
449- },
450- },
451- & logger ,
452- opts ,
453- )
454338 })
455339
456340 It ("redacts every query param from endpoint for https calls" , func () {
@@ -526,46 +410,22 @@ var _ = Describe("HTTPClient", func() {
526410 It ("redacts passwords from error message" , func () {
527411 url := "http://foo:bar@10.10.0.0/path"
528412
529- _ , err := httpClient .GetCustomized (url , func (r * http.Request ) {})
413+ _ , err := fastErroringHttpClient .GetCustomized (url , func (r * http.Request ) {})
530414 Expect (err ).To (HaveOccurred ())
531415 Expect (err .Error ()).To (ContainSubstring ("http://foo:<redacted>@10.10.0.0/path" ))
532416 })
533417
534418 It ("redacts passwords from error message for https calls" , func () {
535419 url := "https://foo:bar@10.10.0.0:8080/path"
536420
537- _ , err := httpClient .GetCustomized (url , func (r * http.Request ) {})
421+ _ , err := fastErroringHttpClient .GetCustomized (url , func (r * http.Request ) {})
538422 Expect (err ).To (HaveOccurred ())
539423 Expect (err .Error ()).To (ContainSubstring ("https://foo:<redacted>@10.10.0.0:8080/path" ))
540424 })
541425
542426 Describe ("httpclient opts" , func () {
543- var opts Opts
544-
545427 BeforeEach (func () {
546428 opts = Opts {NoRedactUrlQuery : true }
547-
548- httpClient = NewHTTPClientOpts (& http.Client {
549- Transport : & http.Transport {
550- TLSClientConfig : & tls.Config {
551- RootCAs : nil ,
552- InsecureSkipVerify : true ,
553- },
554-
555- Proxy : http .ProxyFromEnvironment ,
556-
557- Dial : (& net.Dialer {
558- Timeout : 10 * time .Millisecond ,
559- KeepAlive : 0 ,
560- }).Dial ,
561-
562- TLSHandshakeTimeout : 10 * time .Millisecond ,
563- DisableKeepAlives : true ,
564- },
565- },
566- & logger ,
567- opts ,
568- )
569429 })
570430
571431 It ("does not redact every query param from endpoint for https calls" , func () {
@@ -580,28 +440,6 @@ var _ = Describe("HTTPClient", func() {
580440 Context ("httpclient has been configured to redact query parmas" , func () {
581441 BeforeEach (func () {
582442 opts = Opts {}
583-
584- httpClient = NewHTTPClientOpts (& http.Client {
585- Transport : & http.Transport {
586- TLSClientConfig : & tls.Config {
587- RootCAs : nil ,
588- InsecureSkipVerify : true ,
589- },
590-
591- Proxy : http .ProxyFromEnvironment ,
592-
593- Dial : (& net.Dialer {
594- Timeout : 10 * time .Millisecond ,
595- KeepAlive : 0 ,
596- }).Dial ,
597-
598- TLSHandshakeTimeout : 10 * time .Millisecond ,
599- DisableKeepAlives : true ,
600- },
601- },
602- & logger ,
603- opts ,
604- )
605443 })
606444
607445 It ("redacts every query param from endpoint for https calls" , func () {
0 commit comments