jarcoal / httpmock

HTTP mocking for Golang
http://godoc.org/github.com/jarcoal/httpmock
MIT License
1.93k stars 103 forks source link

Issue while using ActivateNonDefault #76

Closed Bharathhere closed 5 years ago

Bharathhere commented 5 years ago

I'm using ActivateNonDefault for activating the mocks on my custom client but I see it not intercepting the calls. My client is using http.DefaultTransport for transport which I'm passing client := &http.Client{Transport: http.DefaultTransport} httpmock.ActivateNonDefault(client) while activating the client.,I also tried passing the way it is in documentation which did not help me., Can someone help me.,Thanks in advance!

maxatome commented 5 years ago

Are you using the last version v1.0.4? Do you have a reproducible test?

Bharathhere commented 5 years ago

Yes I am on version v1.0.4., To say I'm using it for BDD's and not for unit tests., I have two other mocks for different urls which are working fine but the one with custom client is not working and the error is dial tcp 127.0.0.1:8090: connect: connection refused

maxatome commented 5 years ago

Without a small example of usage, it will be difficult to understand what happens in your case...

Tochemey commented 5 years ago

I am pretty sure that the client you are using the implementation might different from the one in the test. Or you are having two different instance of the client and that makes it impossible for httpmock to intercept the client request.

Bharathhere commented 5 years ago

This got resolved for me. The client I have is not getting intercepted by using NonDefault so I set my clients transport to use the http default transport rester.DefaultTransport = httpmock.DefaultTransport and used httpmock.Activate()