Hi, we are trying to get Pact JVM's matchQuery() t...
# pact-jvm
r
Hi, we are trying to get Pact JVM's matchQuery() to work with PactFlow's Hosted Stubs. Because matching rules are a requirement for us, we are using Pact v2 contracts. In our efforts to try and get dynamic query parameters working, we are facing the below error:
Copy code
Error from Pactflow stub: Pact::Error - Value to generate \"[\"string\"]\" does not match regular expression /[A-Za-z0-9]{1,}/
For reference, we have tried both of the two ways (one including a custom example, and the other not):
Copy code
// Example not included (Pactflow generates randomly)
pactDslRequestWithPath = pactDslRequestWithPath.matchQuery(parameter.getName(), "[A-Za-z0-9]{1,}");
// Example included
pactDslRequestWithPath = pactDslRequestWithPath.matchQuery(parameter.getName(), "[A-Za-z0-9]{1,}", "string");
Here is the relevant part of the contract that was generated:
Copy code
"request": {
   "method": "GET",
   "path": "<path>",
   "query": "response_type=string&client_id=string&redirect_uri=string&state=string&scope=string",
   "matchingRules": {
      <path>,
      "$.query.response_type": {
         "match": "regex",
         "regex": "[A-Za-z0-9]{1,}"
      },
      "$.query.client_id": {
         "match": "regex",
         "regex": "[A-Za-z0-9]{1,}"
      },
      ...
}
We were facing similar issues with machPath() when we were not including the example, but including the custom example worked in that case. Has anyone got this feature working with v2 contracts? Am I missing something?
u
If you look at your error message, you'll notice something odd:
Value to generate \"[\"string\"]\" does not match regular expression /[A-Za-z0-9]{1,}/
, the value has square brackets and quotes around it. That is why it is not matching the regex
r
Yes that part makes sense ... I'm still curious as to why the brackets and quotes are being added in the first place, though. I am just passing in "string" to the matchQuery() function, and I am getting this same error even when I don't provide a default example. Do you know if maybe there is a workaround? Only thing that I can think of is adding the optional brackets and quotes in the regex itself, but that's probably not ideal
u
I think the issue is with PactFlow's Hosted Stubs, as the test code and contract looks ok
I've raised a Jira ticket for this for the dev team to look into
r
Sounds great, thank you!
For traceability purposes, is there a public link for this Jira card and/or would there be an ETA that this will be picked up?
u
Unfortunately, no. It is the internal Pactflow team backlog. Best to raise to a Github issue with the details above and we can use that to track it
y
Hey @Rachel Butler , saw your issue here and dropped you a reply https://github.com/pactflow/example-consumer-java-junit/issues/27
r
Thanks! Will keep track in there
m
FYI I have moved the issue to https://github.com/pact-foundation/pact-mock_service/issues/140, which is where the true source of the problem lies