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

Lack of clarity about the usage of `gock.New` and how it only matches hosts

zacharyarnaise opened this issue · comments

I believe that the documentation isn't clear enough about the fact that only hosts should be passed to gock.New.
It's even more confusing because gock won't raise any errors if you do.

The way things are actually, a gock like this:

gock.New("https://foobar.test/api/v1").
	Get("/some-endpoint").
	Reply(200)

Would match any requests with such URLs: https://foobar.test/<this could be anything>/some-endpoint.

I think that the documentation should make this behaviour more apparent and since it's an expected behaviour, gock.New should raise an error if any part of URL that isn't a host is passed to it.