http mocks regardless of domain
justman00 opened this issue · 2 comments
justman00 commented
Hey,
It looks like httpmock, mocks the HTTP transporter regardless of the domain that is being called.
func Test_mockHTTP(t *testing.T) {
httpmock.Activate()
// I only want to mock the https://some-domain.com
httpmock.RegisterResponder(http.MethodGet, "https://some-domain.com", httpmock.NewStringResponder(http.StatusOK, "hello world"))
client := http.Client{}
// The request should get intercepted
_, err := client.Get("https://some-domain.com")
require.NoError(t, err)
// The request should NOT get intercepted, but it does and fails with Get "https://sumup.com": no responder found
_, err = client.Get("https://gitlab.com")
require.NoError(t, err)
}
If this is not by design, I am happy to submit a PR
maxatome commented
Hello, yes httpmock replaces the net/http.Client
instance by its own. So for each instance, all requests are diverted, it is by design. You can play with RegisterNoResponder
to handle such cases where for a single client you want only mock one domain / URL:
httpmock.RegisterNoResponder(httpmock.InitialTransport.RoundTrip)
justman00 commented
okay, thank you for the quick answer 🙏