-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
Requiring the exact body for an expectation is not scalable #33
Comments
As an example, I currently need to match a body of the following form:
But I'm only interested in the values for event_type, user.id and document.id. And I don't care about the structure, which can change based on some context. I would like to say something like (in ruby like pseudocode):
This code can match both a JSON and XML response. |
This assumes that you're using path matchers to pull the values out of the request/response, in the actual code, yes? |
If this was a get request, how would you specify which event would actually be queried for? |
Ah, I think I see what you mean about not specifying the full body, you're talking about the request, not the response. We allow extra values in the response, but not in the request, because we don't want data to leak out. There is a way to turn off this request validation in the ruby pact library, but because I think it's a bad thing (and Martin Fowler agrees with me!), I've not advertised it :P Do you really think it's a good feature to have? |
yeah, sorry. This is in the consumer test specifying the request matching. |
We absolutely need to keep the Ruby and JVM pacts in sync, regarding The implementation complexity could easily get out of hand here, so we On 2 May 2014 12:17, Ronald Holshausen notifications@github.com wrote:
|
I believe there are actually three features we need to discuss here
|
Incidentally, is there any thought to support any other kind of body than On 2 May 2014 12:48, bethesque notifications@github.com wrote:
|
The ruby implementation doesn't just support JSON, it's just that the best matching/diffing functionality is for JSON. You can specify any content type you like, but it will just do a plain text match on it. There has always been the idea that we'd support XML as well, but nobody involved has been on a project that used XML since we started using it, and nobody has had enough motivation to do it in their free time! |
@uglyog , if you do this, your request body will match if there are extra values in your request body, however, as you probably remember, what gets written to the pact file is the expected request, no the actual request, so you'd be missing the values you didn't specify, which may upset the provider. {
:method => :post,
:path => '/contract-pricing',
:headers => {
'Content-Type' => 'application/json;charset=utf-8',
'Accept' => 'application/json, text/plain, */*'
},
:options => {:allow_unexpected_keys_in_body => true}
} As you can see, all the dodgy hacks in pact were made to support Condor :P |
Hmm, it looks like the pact-jvm does not allow unexpected keys in the body (it is set in a constant to false). I've done some hackery to get it to work for me by changing the constant to a var, but it should have options as per the ruby one. I'm wondering if the actual request should be recorded for the pact verification. For my case there are values that I will not know before hand, but they will be required for the validation with the provider to succeed. |
The request doesn't allow extra keys, the response does, I thought that was in line with the ruby version. There's a PactServerConfig case class which could / should be used for settings like this |
You were right in your assumption Trav, it's not supposed to be a feature, it was a hack I made to support Condor. Ron, we'd need to move the pact serialization to the mock server if we were to use the actual request. I'm not convinced this is a good thing though. Wouldn't type based matching be a better option for the values that are unknown beforehand? |
Type based matching would work, but then we need a regex format that works across both implementations ;-) |
The gist that I sent you the other day was a plan for both type based matching and regexps. I think the majority of the time, we want type based matching, and then occasionally, we want exact value or generate/regexp. |
So other people can see what I'm talking about, this https://gist.github.com/bethesque/5a35a3c1cb9fdab6dce7 is an idea I've been working on to allow type based and regexp based matching. The thoughts I went through to get to that I've documented here: https://gist.github.com/bethesque/39c42c8feff308481449 |
Closing this as regexp matching based on the 2.0 spec has been implemented |
You're smashing it Ron. Keep up the good work! On 9 October 2014 09:17, Ronald Holshausen notifications@github.com wrote:
|
Having to provide the exact body for a request is not scalable. Have a look at the resulting ruby pact issue #1
My current project has json bodies that include UUIDs and timestamps, which will never be known beforehand.
By adding a path to a matcher, it would mean I could only match on the things that are important in the body.
The text was updated successfully, but these errors were encountered: