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
"Apply matching rules using the first element of the spec array" #11
Comments
Is this an actual issue you've run into? I just created a new test case based on what you've written above, and the current code passes the test case. For your reference, the test case I wrote is:
|
There are specific test cases in the pact specification that relate to this: testcases/response/body/array in different order.json (specifies that each element is tested when running an equality match) testcases/response/body/array with type matcher.json (specifies only one element in the expected body, this only one element's type can be applied to all elements in the actual) |
okay, i think i found the issue. the reproducehere's our response body test json. i'm too tired to remember why adding the matching rule gets us into the {
"match": true,
"comment": "identical lists match",
"expected": {
"headers": {"Content-Type": "application/json"},
"body": {
"letters": ["a", "b", "c"]
},
"matchingRules": {
"body": {
"$.letters[2]": {"matchers": [{"match": "type"}]}
}
}
},
"actual": {
"headers": {
"Content-Type": "application/json"
},
"body": {
"letters": ["a", "b", "c"]
}
}
}
running the tests as is should pass. but, if you change: pactman/pactman/verifier/verify.py Line 330 in 7cb23a4
to return self.result.fail('oops') the test case for this test should fail. what's happening is, on the second iteration of the pactman/pactman/verifier/verify.py Line 221 in 7cb23a4
which should fail verification, but the calling function only returns False and self.result.fail is never called.
notemaybe there is a reason that the test cases are okay with |
this is where having the matching rule present sends us down the pactman/pactman/verifier/verify.py Lines 188 to 190 in 7cb23a4
|
also can be done more simply with: {
"match": true,
"comment": "identical lists match",
"expected": {
"headers": {"Content-Type": "application/json"},
"body": ["a", "b", "c"],
"matchingRules": {
"body": {
"$[2]": {"matchers": [{"match": "type"}]}
}
}
},
"actual": {
"headers": {
"Content-Type": "application/json"
},
"body": ["a", "b", "c"]
}
} |
Thank you so much for the investigation! I'll get a patch out asap. |
In general there shouldn't be a failure without a |
no problem! stepping through new code bases is always a fun adventure, ha. i'm curious to see your patch for this. unfortunately (or fortunately?) i believe this uncovers a few other false positive tests in the test suite against the pact specification cases. i experimented with some simple fixes to patch the bug in my free time but realized it was quite difficult. |
I've added a test to the json testcases code to check that there's a fail() called for each time it's actually failed. That's turned up a few places which I'll look at addressing, yep. |
Some failing testcases were being falsely passed because the failure was not being correctly detected. Mostly this was around the appropriate application of matching rules, where several bugs have been fixed: - confusing between rule paths being "headers" vs. "header" in v2/v3 - "path" rule paths were being incorrectly prefixed internally in v3 - array element iteration was always treating the spec as a single sample, breaking rules applying to specific array elements fixes #11
@zhammer please give that branch a try and let me know whether it addresses your issue |
my pact verifies now! |
Excellent! |
pactman/pactman/verifier/verify.py
Line 325 in 7cb23a4
Out of curiosity: is this behavior part of the pact specification?
It seems odd to me that I wouldn't be able to verify the pact:
provider:
AlphabetService
upon_receiving:
/alphabet?limit=3
responds_with:
'letters': ['a', 'b', 'c']
matching_rules: None
with the response:
'letters': ['a', 'b', 'c']
, since eachdata_elem
will be compared not with its correspondingspec_elem
, but with the first element in the spec. (i'll get the errordata[1] 'b' does not equal spec 'a'
.i could understand if the idea is that expecting an exact array from a provider is too fragile and we should only look for general list matches, but just want to confirm!
The text was updated successfully, but these errors were encountered: