question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Matching rules against field name with a '.' character are not working

See original GitHub issue

Hi,

I’m currently trying to test a contract with an Odata v4 endpoint.

As part of the Odata json format specifications the server usually includes information other than the raw data in the response called annotations.

Annotations are name/value pairs that have a dot (.) as part of the name, an example could be

"@odata.context": "http://localhost/$metadata#MyEntity/$entity"

Obviously I’m not interested in the exact value of the annotations field so I’m using type matchers and my pact looks something like:

{ "consumer": { "name": "OdataConsumer" }, "provider": { "name": "OdataProvider" }, "interactions": [ { "description": "A GET request to retrieve an Odata entity", "request": { "method": "get", "path": "/odata/MyEntity('1234')" }, "response": { "status": 200, "headers": { "Content-Type": "application/json; odata.metadata=minimal", "OData-Version": "4.0" }, "body": { "@odata.context": "http://localhost/$metadata#MyEntity/$entity", "anotherField": "someDataHere" }, "matchingRules": { "$.body.@odata.context": { "match": "type" }, "$.body.anotherField": { "match": "type" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }

As you can see the matching rule is not correctly escaping the annotation name and, as a result, it won’t be executed. My understanding is that the (.) is interpreted as a path separator.

Is there any way to fix this behavior having matching rules working against fields with a (.) as part of their names?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:41 (36 by maintainers)

github_iconTop GitHub Comments

1reaction
GiampaLabcommented, Aug 29, 2017

Thank @neilcampbell, @bethesque , @uglyog I just tested the new beta release and it’s working correctly, well done!

Also we are working on a library which makes producer tests trivial to implement and supports branching you can find it here

Let me know what you think!

Thanks

1reaction
uglyogcommented, Aug 28, 2017

In Pact JVM there are the following values for JSON bodies:

  • Empty body (the Content-Length header will have a value of 0)
  • Empty string body (represented by the empty JSON string "", Content-Length will probably = 2)
  • Null body (represented by the JSON null value, Content-Length will probably = 4)
  • JSON body, which could be a number, true, false, a string, an array or an object.

In the Pact file, we represent no body and empty body differently:

Empty string bodies are a difficult one. The only way to represent it correctly is with escaped strings, e.g. "\"\"".

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matching rules against field name with a '@' character are ...
Hi, I would like to use the code as mock on consumer: // build the request $request = new ConsumerRequest(); $request ->setMethod('POST') ...
Read more >
Things to Know Before You Customize Matching Rules
If a field on an object is no longer available in your org, it can cause matching rules with mappings to this field...
Read more >
Matching Methods Used in Matching Rules
The matching method determines how a specific field in a record is compared to the same field in another record. Each matching method...
Read more >
Defining the Match Process by Creating Rules
Setting rule conditions determines which attributes must be matched together, and whether they must exactly match, or whether a tolerance is allowed.
Read more >
Working with string match conditions - AWS Documentation
If you want to allow or block web requests based on strings that appear in the requests, create one or more string match...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found