-
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
Allow multiple matchers #26
base: master
Are you sure you want to change the base?
Conversation
This looks promising :) |
request.go
Outdated
@@ -48,7 +48,7 @@ type Request struct { | |||
Cookies []*http.Cookie | |||
|
|||
// BodyBuffer stores the body data to match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct godoc: // BodyBuffer
-> // BodyMatchers
request.go
Outdated
return r | ||
} | ||
|
||
// BodyString defines the body to match based on a given string. | ||
func (r *Request) BodyString(body string) *Request { | ||
r.BodyBuffer = []byte(body) | ||
var bodyBuffer []byte | ||
bodyBuffer = []byte(body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the single-line DRYer version: bodyBuffer := []byte(body)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even: r.BodyMatchers = append(r.BodyMatchers, []byte(body))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. Got a little too zealous with my copy/paste job :)
After a quick review, it looks great. Thanks for adding the test cases too. My only concern is that this introduces a different behavior that can also affects to other matchers, not just the body, so I want to think about it before introduce this feature. Thanks for the PR! |
In essence, I feel like the final goal of this implementation is introducing a different approach of what is currently implemented in Overtime I realized that this approach would be more flexible, so I have implemented it in pook, a sort of Python port of I'm not close to this port this approach into |
I'm on vacation next week, so I'll probably have some time to do more work on this PR. I'm just going to mess around a bit and see if I can make some improvements (maybe even take a stab at implementing your concept of a deferred 'matcher function'). I'll keep you updated. No worries if you don't want to merge. |
Cool, any help would be very welcome. Feel free to update me here with your ideas or approches, so we can converge somehow. |
Any updates here? Just curious :) |
Just tagging in here but I'am down to contribute as well =)! I like the your idea about registering matcher functions for later use. |
Finally getting some time to start working on the rehaul of the matcher functions. I'll be making a separate PR when I've got something to share. |
Any update here? |
Hey @h2non I looked again at this PR and had a few thoughts about how to go forward from here. I don't think we should be defining multiple body matchers in a single matcher and I don't think it should be overwriting the previous definition either. Ideally, I'll take a swing at this soon :) |
better diff view
I had a slightly confusing moment the other day when I was using
gock
. I had code very similar to the following:To my surprise,
gock
did match the request. The source code makes the issue pretty clear: the second call toBodyString()
just overwrote the first. This didn't seem like intuitive behavior to me.This PR aims to remove this confusion by allowing multiple matchers (of the same or different types). I'm not necessarily finished with the PR; I think there might be a more generic/cleaner way of accomplishing this. But I wanted to go ahead and publish the PR so I could get some feedback on the general idea.