-
Notifications
You must be signed in to change notification settings - Fork 107
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
AddMatch #20
Comments
I use Filter solve this problem `func filter(req *http.Request) bool { func test_a() {
}` |
Same here. So the matchers somehow live forever in your stack even if you call gock.Off()? Is this a feature or a bug? I could work around by using filters too. |
@JusbeR It's intended. If you want to clean any unmatched request from the mock store, you should call |
Hmm, it feels like I am not getting something here now. If I run this:
I get:
Which should not happen after the |
It does this probably because we modify the DefaultMathcer. I tried to add |
I just ran into this, and agree that the problem is that The result: the presence of an My workaround for now is to change this:
to this:
This assigns the mock a brand-new matcher object. The new matcher has the same battery of matching functions that Though this seems to work, I am not happy with this solution – few programmers are going to expect
Thoughts? |
@ods94065 Thanks for the comment here. I review the issue and your points makes sense to me. I don't recall why I have decided to modify package-level state to be honest, but reviewing it now, I think it was a design mistake. Options 1 and 2 seems reasonable to me and it's pretty much what I had in mind. Will push a fix soon. I might have some negative side-effects to some users, but I will not consider it a breaking change. The good thing about the option 2 is that users that want to have globally shared matches can still rely on it by using |
@h2non Any progress on this? I just hit the same bug, and I'm happy to spend some time fixing it using one of the above suggestion if that helps |
AddMatch only use once in a go program?
package main
import (
"fmt"
"net/http"
"regexp"
"gopkg.in/h2non/gock.v1"
)
func test_a() {
defer gock.Off()
}
func test_b() {
defer gock.Off()
gock.New("http://httpbin.org").
Get("/application").
Reply(200).
SetHeader("Server", "gockbin")
}
func main() {
test_a()
test_b()
}
The text was updated successfully, but these errors were encountered: