h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

Home Page:https://pkg.go.dev/github.com/h2non/gock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How to mock two urls and corresponding responses.

ziranl16 opened this issue · comments

commented

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?

commented

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).

commented

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).

Thanks!!