[Question] How to mock two urls and corresponding responses.
ziranl16 opened this issue · comments
Hi guys, gock is a great project! However, in my current work, I have a method that will call two different APIs. In our current work, this is currently inevitable.
Thus, I hope to mock two urls in one test and return two corresponding responses. I wonder if there is a way for me to achieve this?
You can simply define the two URLs to mock before the actual method call in your test.
Assuming both HTTP calls work use http.DefaultTransport
instance within the same Go process, there is not further action required. However, if the HTTP calls uses a custom instance of http.Client
, then you will have to explicitly intercept those instances by using gock.InterceptClient(*http.Client)
.
You can simply define the two URLs to mock before the actual method call in your test.
Assuming both HTTP calls work use
http.DefaultTransport
instance within the same Go process, there is not further action required. However, if the HTTP calls uses a custom instance ofhttp.Client
, then you will have to explicitly intercept those instances by usinggock.InterceptClient(*http.Client)
.
Thanks!!