Open nsfrias opened 1 year ago
I also attempted to change the type on the pact-go library (matcher_v3.go
) to eachValue
as other comments on related issues suggested was the correct approach.
// Object where the key itself is ignored, but the value template must match.
//
// key - Example key to use (which will be ignored)
// template - Example value template to base the comparison on
func EachKeyLike(key string, template interface{}) Matcher {
return eachKeyLike{
Specification: models.V3,
Type: "eachValue",
Contents: template,
}
}
This is the rule generated
DocPath { path_tokens: [Root, Field("extraInfo")], expr: "$.extraInfo" }: RuleList { rules: [EachValue(MatchingRuleDefinition { value: "{\"pact:matcher:type\":\"type\",\"specification\":\"2.0.0\",\"value\":\"folk\"}", value_type: Unknown, rules: [], generator: None }), Type], rule_logic: And, cascaded: false }
However the test also failed, albeit with a different error:
2023/04/05 11:28:44 [INFO] pact validation failed, errors:
Expected 'folk' to be the same type as '{"genre":"folk"}'
expected: "folk"
actual: {"genre":"folk"}
The example was also wrong:
2023-04-05T10:28:44.196839Z DEBUG tokio-runtime-worker pact_matching: body: '{"author":"Mark Twain","book":"The Adventures of Tom Sawyer","extraInfo":"folk"}'
I think it's a matter of changing the value of this attribute on the matcher to eachKey
.
If you wanted to attempt a PR and check if it resolves, that would be super helpful!
Thanks @mefellows I'll try your suggested fix and create a PR for it.
Thank you!
👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-1056). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.
See our documentation for more information.
Waiting on upstream clarification: https://github.com/pact-foundation/pact-reference/issues/299
Software versions
go version go1.18.3 darwin/arm64
go env
Expected behaviour
Given a request body like:
I expect a contract with the following rules for the request body to match (all else being OK):
Actual behaviour
Given the previous request body and contract rules I get the following error:
Looking at the log I see the pact expected request is also wrong:
Steps to reproduce
You can run this test to reproduce the issue:
Relevent log files
eachkeylike_issue.log