Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zacharyarnaise opened this issue Jul 23, 2023 · 1 comment

Comments

@zacharyarnaise
Copy link

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.

@ImFlog
Copy link

ImFlog commented Oct 1, 2024

I also stumbled upon an issue of the same kind I think.

If I have an URL that looks like: https://somewhere-over-the-rainbow.com
And another one like: https://tsomewhere-over-the-rainbow.com

If i define mocks on each URLs, they may be matched by the first URL (without the t). There is probably something that checks with wildcard before the host or something ?
This was quite a confusing debug moment 😅

Edit: after looking at the documentation again it seems that the option DisableRegexpHost might be what I was looking for ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants