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

http2 client mock support

ostronom opened this issue · comments

Are there any plans to support http2 transport mocking?

commented

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?

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.

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