pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

Message pact is being compared without matchers #1509

Open sanderdeneve-tomtom opened 2 years ago

sanderdeneve-tomtom commented 2 years ago

In one project, I'm using MessagePactBuilder from dependency au.com.dius.pact:consumer:4.3.4 to build a spec:

{ "consumer": { "name": "My Consumer" }, "interactions": [ { ... "contents": { "content": { "after": 1, "before": 1, "userId": 1 }, "contentType": "application/json", "encoded": false }, "description": "some description", "key": "c6dda921", "matchingRules": { "content": { "$.after": { "combine": "AND", "matchers": [ { "match": "number" } ] }, "$.before": { "combine": "AND", "matchers": [ { "match": "number" } ] }, "$.userId": { "combine": "AND", "matchers": [ { "match": "number" } ] } } }, "metadata": { "LogicalResourceId": "foo", "contentType": "application/json" }, "pending": false, "type": "Asynchronous/Messages" } ], "metadata": { "pact-jvm": { "version": "4.3.4" }, "pactSpecification": { "version": "4.0" } }, "provider": { "name": "My Provider" } }

Make note of the matchingRules with key content.

Now when I run the pact on the provider side, it fails with this error message:

1) some description: generates a message which has a matching body 1.1) body: $.after Expected 1 (Integer) but received 4 (Integer) 1.2) body: $.before Expected 1 (Integer) but received 3 (Integer) 1.3) body: $.userId Expected 1 (Integer) but received 2 (Integer)

After some debugging, it looks like the following line is always taking body as a category: https://github.com/pact-foundation/pact-jvm/blob/54df7cf6a91676f8e6ad3f17adeff3e4ce4aeeb7/provider/src/main/kotlin/au/com/dius/pact/provider/ResponseComparison.kt#L179

This feels like a bug, wdyt?

EDIT: this seems to be linked solely to V4, as V3 sets the matchingRules with key content

uglyog commented 2 years ago

Yes, this does look like a bug

achawla-Branch commented 2 years ago

I stumbled on same issue. @uglyog do you have any plan to fix this in the near term? Thanks