-
Notifications
You must be signed in to change notification settings - Fork 109
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
Is possible to enable verbose mode to see all requests which cross Gock? #32
Comments
There's no verbose mode. You can partially inspect not mocked/matched HTTP requests by calling: What I would be open to considering is first-class support for easy to use traffic observers instead of a generic debugging layer, for instance: gock.Observe("request", func (req *http.Request, mock gock.Mock) {
// do whatever you need with the request, such as:
log.Printf("Incoming request: %#v", req)
})
gock.Observe("mock", func (req *http.Request, mock gock.Mock) {
// do whatever you need with the request, such as:
log.Printf("Mocked request: %#v", req)
}) Observers can be only used for read-only, side-effects free traffic observation, not for control flow, filtering, transformation... That way the developer can easily implement and integrate its preferred debugging mechanism. |
I wouldn't mind picking this up. I spend a fair bit of time debugging requests that don't match and usually point to my forked gock with this change: steinfletcher@8f86c0d @h2non this is similar to your proposal but without the Cheers |
@steinfletcher Thanks. Nice job. It looks good for an initial implementation, but I would like to be able to differ between outgoing requests and actually matched mocked requests. Implementing an observer mechanism based on events looks solid and versatile to me. Feel free to send the PR and we can iterate from that. |
@h2non Great. So is the My use case is when a match fails I want debug why it doesn't match, I wonder if it might be a little too complex to perform a diff - especially when there are several registered mocks. It might be enough to just look at the outgoing requests and eyeball the difference. The Let me know what you think and I'll submit a PR :) |
Yes, Diff mechanism should be out of the responsibility here. Users are always welcome to implement it by themselves.
Yes, I think so. The underlying goal here is to provide a more simple inspect/debug mechanism, but also giving flexibility to users if they want to implement fine-grained inspection.
That's fine. We can implement as you suggest in the default built-in debugger/observer function.
|
Thanks for your input @h2non, I'll get back to you in the near future with a PR |
I found a new use case for this feature. At Sainsburys we use gock for our behavioural/black box api tests. So this enables us to intercept the requests and auto generate sequence diagrams from the test: Example here: https://htmlpreview.github.io/?https://github.com/steinfletcher/gock/blob/feature/diagram/sequence-diagram.html |
Hi,
is possible to enable verbose mode to see all requests which cross Gock?
If not, I suggest to add it, it is very useful to debug.
Best regards,
Stéphane
The text was updated successfully, but these errors were encountered: