Here's neat testing trick I've just come across.
I've got an HTTP client that makes requests to https://accounts.google.com.
So I create a fake HTTP server:
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
/// ...
})
And then I can force my HTTP client to make non-HTTPS connections to my local server
&http.Client{Transport: &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
address := srv.Listener.Addr()
return net.Dial(address.Network(), address.String())
},
}}