jarcoal/httpmock

how httpmock works with InsecureSkipVerify

chrislinan opened this issue · 2 comments

I am using httpmock test my function, in my function, I have a line as follow:
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
And when I run my test, there is an error shows:

panic: interface conversion: http.RoundTripper is *httpmock.MockTransport, not *http.Transport

If I remove this line , the test runs normally. But I need this line of code. Could you help on this ?

Hello,
It is better to not modify the http.DefaultTransport content, but use your own transport first copied from it.
If you still want to do it, just do:

if ht, ok := http.DefaultTransport.(*http.Transport); ok {
  ht.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}

Hi @maxatome
That works for me. Thanks a lot.