httmock not working with resty
heronrs opened this issue · 2 comments
heronrs commented
I have this small code block to test resty + httpmock but the requests is not being intercepted.
I'm getting the google page html as a response.
Am I missing anything?
package main
import (
"fmt"
"github.com/go-resty/resty/v2"
"github.com/jarcoal/httpmock"
)
func main() {
client := resty.New()
httpmock.ActivateNonDefault(resty.New().GetClient())
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://google.com",
httpmock.NewStringResponder(200, `[{"id": 1, "name": "My Great Article"}]`))
resp, _ := client.R().
Get("https://google.com")
fmt.Println(resp)
}
maxatome commented
Hi
That is because you don't enable httpmock on the right client. Do this instead:
httpmock.ActivateNonDefault(client.GetClient())
heronrs commented
Hey sorry for the delay. It worked. Thanks!