jarcoal / httpmock

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

Be able to handle non-default http clients #6

Closed timkaye11 closed 9 years ago

timkaye11 commented 9 years ago

In order to enable mock testing, we currently replace the http.DefaultTransport with the mock transport in the Activate function. However, we run into errors when we use clients other than http.DefaultClient (which uses the default transport). In order to handle non-default clients, this PR introduces the ActivateNonDefault function, which replaces custom the http.Transport with the mock transport for custom http.Clients.

Also bumped travis to the newest version and added a unit test for the new function.

pires commented 9 years ago

+1

@timkaye11 Can this be used to work with github.com/parnurzeal/gorequest?

timkaye11 commented 9 years ago

@pires I believe so - you'd just have to call ActivateNonDefault(s.Client) where s is the SuperAgent. https://github.com/parnurzeal/gorequest/blob/master/main.go#L565

pires commented 9 years ago

@timkaye11 didn't work.

pires commented 9 years ago

@timkaye11 what is now obvious to me is that I had to comment the line you linked and it worked. Ofc, commenting said line will break runtime.

jarcoal commented 9 years ago

@timkaye11 thanks!