Skip to content
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

Hosted Stubs - matchQuery() not working as expected with v2 contracts #27

Closed
rebutler97 opened this issue Oct 28, 2022 · 4 comments
Closed

Comments

@rebutler97
Copy link

Hi, I'm hoping that I raised this issue under the correct repository. I already raised this in slack.pact.ioand I was told to raise an issue to track. There was also an internal Jira raised to look into.

We are trying to get Pact JVM's matchQuery() to work with PactFlow's Hosted Stubs. Because matching rules are a requirement for is, we are using Pact v2 contracts.

In our efforts to try and get dynamic query parameters working, we are facing the below error:

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):

// 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:

"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 matchPath() when we were not including the example, but including the custom example worked in that case.

Has anyone gotten this feature working with v2 contracts? Am I missing something?

I have tried workarounds like adding an extra bracket and quotes to the regular expression, but a) that is not ideal and b) it still didn't work. Any guidance would be much appreciated.

@YOU54F
Copy link
Member

YOU54F commented Oct 28, 2022

Hey @rebutler97!

This probably isn't the right repo, but not sure where the right one would be for this at the moment? maybe our public roadmap https://github.com/pactflow/roadmap

Anyway that probably doesn't help you for now, so let's not worry about that - there is an internal ticket the dev team will track

I don't mind helping out for the time being!

A few things that would be useful for me and others if they wish to help.

I assume you are writing a test, with pact jvm, which is generating a v2 contract. This is being uploaded to Pactflow, and you are trying to access that with something?

  1. Could you create a repo that uses the same libraries, that generates the pact (maybe fork and modify this one if suitable?) - whilst you are doing this, could you provide me the output pact file?
  2. Could you let me know how and in what context you are accessing the hosted stubs. Could you provide a curl command or similar that you are using.

Related slack post in pact-jvm https://pact-foundation.slack.com/archives/C9UN99H24/p1666709918005809

@rebutler97
Copy link
Author

Apologies for delay, I just forked and pushed minor changes: https://github.com/rebutler97/example-consumer-java-junit-queryparams
Please note that I am behind a company firewall so unfortunately I am not able to run this application, but I only added one line for matchQuery(). I have also attached the contract that I generated using the original application. Below is the error message I received:

{
    "error": {
        "message": "Error from Pactflow stub: Pact::Error - Value to generate \"[\"S\"]\" does not match regular expression /[A-Za-z0-9]{1,20}/",
        "reference": "sTxZyymKcf"
    }
}

Also, because our Pactflow is hosted within our company, I am unable to share a working curl command. However, it should look something like this:
curl --location --request GET 'https://<pactflow-url>/pacts/provider/sample-provider/consumer/sample-consumer/latest/stub/product/10?param=string'
Please let me know if you need any more information from me!

@rebutler97
Copy link
Author

Is this enough information to look into?

@mefellows
Copy link
Contributor

Hi @rebutler97 - apologies I missed this, we don't track issues on the test examples in the same way as product backlog. Apologies for any confusion.

The issue is in the open source component pact-stub-service which Pactflow uses for this feature.

I've raised the bug there: pact-foundation/pact-mock_service#140

I'll close this one off so we can follow appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants