Closed julio-vaz closed 5 years ago
For anyone looking for a solution, it's called DisableTransportSwap
and must be set like this on the gorequest
package:
gorequest.DisableTransportSwap = true
Also see https://github.com/parnurzeal/gorequest/pull/59/files
@julio-vaz Hi,did u find a solution for this? @tedeh And l just use the simple http package in golang.
I'm also having this issue. It works fin in 1.7.5 but as soon as we migrated to 1.8.1 all the tests that were dependent on HTTPMock broke. Is there any update from the maintainer @jarcoal on this?
@onetwopunch Regarding your issue: That's weird. All the tests pass in 1.8 (added to Travis in #30), and it also works on a library I'm working on in 1.8. Here's a test that's working. Are you perhaps using other libraries that might swap out Go's default transport? This seems to have have been an issue with the gorequest
package according to @tedeh's comment above.
Regarding the maintenance of this repo: @jarcoal is no longer maintaining the repo. He added myself and @SchumacherFM as maintainers a while ago.
Seems like people are relying on the global http.Client ... then swapping out transport in parallel situations and wondering why it breaks. In my own projects I never rely on the global http.Client and its Transport. I can also be wrong with my above assumptions ;-)
@dlebech I'm not sure how this works in 1.8.1 given that http.Transport no longer supports RegisterResponder
. This is likely my naive understanding of the library, but I ended up removing httpmock in favor of creating my own RoundTripper implementation and injecting the client, which I think is a much better design choice than overwriting a DefaultTransport globally for the scope of the test (someone else added this library since it works similarly to WebMock in Ruby). Anyway, thanks for the response 🙂
@onetwopunch I'm not completely sure what you mean by "http.Transport no longer supports RegisterResponder
" since this was never a native feature of Go?
Either way, httpmock actually does provide a way to use a non-default client but it is admittedly not well documented in the README. Instead of calling Activate()
you can call ActivateNonDefault(client)
with a client of your choice. Here's a test that shows this behavior. I'm not sure if this fits your use case, but just throwing it out there :)
@julio-vaz ActivateNonDefault(client)
should do the work. If you still encounter a problem, please comment or re-open.
I'm trying to mock a URL that a function requests at the package I'm testing and it still executes the request to the original URL instead of the mocked one that we defined. Is there support for acessing mocked urls at package functions or only inside the test?
Thanks in advance!