Closed heronrs closed 4 years ago
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) }
Hi That is because you don't enable httpmock on the right client. Do this instead:
httpmock.ActivateNonDefault(client.GetClient())
Hey sorry for the delay. It worked. Thanks!
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?