h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
https://pkg.go.dev/github.com/h2non/gock
MIT License
2.09k stars 107 forks source link

http2 client mock support #19

Open ostronom opened 7 years ago

ostronom commented 7 years ago

Are there any plans to support http2 transport mocking?

h2non commented 7 years ago

HTTP/2.0 should be transparently and implicitly supported. gock works at higher level than L7, then no network layer is actually involved.

Are you having any troubles?

ostronom commented 7 years ago

Yes, i do have trouble with http2 client.

func apnsMatcher(r *http.Request, g *gock.Request) (bool, error) {
    fmt.Printf("URL = %s", r.URL.Path)
    return true, nil
}

gock.New("https://api.push.apple.com").
        AddMatcher(apnsMatcher).
        Persist().
        Reply(200).
        JSON(result)

And when I do request anything at https://api.push.apple.com/some/path using apns2 client (it uses http2 transport), I see nothing in the console.

tomas-fp commented 7 years ago

Are you using a custom http.Client, instead of http.DefaultClient? In that case, you should instrument gock on it first. See: https://github.com/h2non/gock/blob/master/_examples/custom_client/client_test.go#L18-L20