@@ -200,19 +200,39 @@ func (fakeHTTPClient) Do(*http.Request) (*http.Response, error) {
200200 return nil , nil
201201}
202202
203- func (fakeHTTPClient ) RoundTrip (* http.Request ) (* http.Response , error ) {
203+ type fakeTransport struct {}
204+
205+ func (fakeTransport ) RoundTrip (* http.Request ) (* http.Response , error ) {
206+ return nil , nil
207+ }
208+
209+ type fakeAltTransport struct {
210+ insecure bool
211+ }
212+
213+ func (f * fakeAltTransport ) RoundTrip (* http.Request ) (* http.Response , error ) {
204214 return nil , nil
205215}
206216
217+ func (f * fakeAltTransport ) SetInsecureTransport () {
218+ f .insecure = true
219+ }
220+
207221// TestSetInsecureMode test if setInsecureMode panic when given custom HTTP client
208222func TestSetInsecureMode (t * testing.T ) {
209223 var buf bytes.Buffer
210224 logger .DefaultLogger .Init (& buf , logger .LogLevelWarning )
211225
212226 // custom Transport client
213227 clientWithFakeTransport := newHTTPClient ()
214- clientWithFakeTransport .Transport = fakeHTTPClient {}
228+ clientWithFakeTransport .Transport = fakeTransport {}
229+ setInsecureMode (clientWithFakeTransport )
230+
231+ // custom Alt transport client
232+ customTransport := & fakeAltTransport {}
233+ clientWithFakeTransport .Transport = customTransport
215234 setInsecureMode (clientWithFakeTransport )
235+ testhelpers .Equals (t , true , customTransport .insecure )
216236
217237 // custom HTTP client
218238 setInsecureMode (fakeHTTPClient {})
@@ -222,7 +242,7 @@ func TestSetInsecureMode(t *testing.T) {
222242 getLogMessage := func (s string ) string {
223243 return strings .Join (strings .Split (s , " " )[3 :], " " )
224244 }
225- testhelpers .Equals (t , "client: cannot use insecure mode with Transport client of type scw.fakeHTTPClient " , getLogMessage (lines [0 ]))
245+ testhelpers .Equals (t , "client: cannot use insecure mode with Transport client of type scw.fakeTransport " , getLogMessage (lines [0 ]))
226246 testhelpers .Equals (t , "client: cannot use insecure mode with HTTP client of type scw.fakeHTTPClient" , getLogMessage (lines [1 ]))
227247
228248 logger .DefaultLogger .Init (os .Stderr , logger .LogLevelWarning )
0 commit comments