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

FFI > Using regex matcher for query: Should apply regex to all values, not just the first value #332

Closed
tienvx opened this issue Oct 24, 2023 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@tienvx
Copy link
Contributor

tienvx commented Oct 24, 2023

I'm trying to match query to contain multiple values using ffi call but it doesn't work as I expected.

FFI call:

pactffi_with_query_parameter_v2($interactionId, 'pages', 0, '{"value":"1","regex":"\\d+","pact:matcher:type":"regex"}');

Http client query:

?pages=2&pages=3

Trimmed logs about matching rule:

2023-10-23T01:46:59.767978Z DEBUG tokio-runtime-worker pact_matching:      matching_rules: MatchingRules { rules: {QUERY: MatchingRuleCategory { name: QUERY, rules: {DocPath { path_tokens: [Root, Field("pages"), Index(0)], expr: "$.pages[0]" }: RuleList { rules: [Regex("\\d+")], rule_logic: And, cascaded: false }} }} }

Expected: No mismatches for pages

Actual: Mismatches with logs:

2023-10-23T01:46:59.768473Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: [QueryMismatch { parameter: "pages", expected: "", actual: "3", mismatch: "Expected query parameter 'pages' with value '' but was '3'" }, QueryMismatch { parameter: "pages", expected: "[\"1\"]", actual: "[\"2\", \"3\"]", mismatch: "Expected query parameter 'pages' with 1 value(s) but received 2 value(s)" }]

For more information:

@tienvx
Copy link
Contributor Author

tienvx commented Oct 24, 2023

Similar ffi function pactffi_with_header_v2 has this note:

NOTE: If you pass in a form with multiple values, the index will be ignored.

Probably we can implement a similar behavior for pactffi_with_query_parameter_v2? For example, change value from '1' to ['1', '2', '3'] like this:

pactffi_with_query_parameter_v2($interactionId, 'pages', 0, '{"value":["1", "2", "3"],"regex":"\\d+","pact:matcher:type":"regex"}');

Then the index 0 will be ignored

@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Oct 25, 2023
@rholshausen
Copy link
Contributor

If you specify the value as an array (i.e. "value":["1"]) it will work as expected.

@tienvx
Copy link
Contributor Author

tienvx commented Oct 28, 2023

It works as expected, see pact-foundation/pact-php#353

I will close this issue now, as it's not a bug.

@tienvx tienvx closed this as completed Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants