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

Matchers: Using time matcher in a query parameter failing verification #483

Open
surpher opened this issue Jan 27, 2025 · 1 comment
Open
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@surpher
Copy link

surpher commented Jan 27, 2025

🌎 Environment

  • Platform: pact_ffi
  • Version/Release: 0.4.25
  • Pact spec: v3, v4
  • FFI used:
bool pactffi_with_query_parameter_v2(
 InteractionHandle interaction, 
 const char *name, 
 size_t index, 
 const char *value
);

💬 Description

Setting up unit tests for PactSwift verifying various query parameter usage including time and datetime matchers. When executing the API request and Pact verification, verification fails:

QueryMismatch: Unable to match ["12:13:00"] using Time("HH:mm:ss")
  Expected: ["12:13:00"]
  Actual: ["12:13:00"]
  Parameter: $.item])"

🦶 Reproduction Steps

Steps to reproduce the behaviour:

  1. Setup a pact interaction that expects a query parameter,
  2. Set query parameter with a time (or datetime) value matching the matcher’s format, ie: 10:13 or 10:13:00,
  3. Set query parameter’s matching rule "pact:matcher:type”: "time”, ”format”: “HH:mm” (or HH:mm:ss),
  4. Trigger GET /endpoint?value=12:13:00,
  5. Verify pact interaction.

🤔 Expected Results

  • Pact test should succeed when GET request contains exactly the same query parameter as set for the value of the matcher.
  • Pact test should succeed when GET request contains any valid (date)time value matching the (date)time format set in the matcher

😲 Actual Results

Pact test fails when using Time matcher and sending the request with query parameter value matching the time format set in pact matcher.
Pac test fails when using Datetime matcher and sending the request with query parameter value matching the datetime format set in pact matcher.

🌳 Logs

...
2025-01-27T23:15:27.336721Z TRACE ThreadId(02) pactffi_create_mock_server_for_transport{pact=PactHandle { pact_ref: 10669 } addr=0x600000c6a2a0 port=4224 transport=0x600000c6a420 transport_config=0x0}:
 pact_ffi::mock_server::handles: with_pact before - ref = 10669, 
inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "Consumer" }, provider: Provider { name: "Provider" },
interactions: [SynchronousHttp { id: None, key: None, description: "an interaction with item matching time", provider_states: [], 
request: HttpRequest {
 method: "GET", 
 path: "/interaction", 
 query: Some({"item": [Some("12:13:00")]}), 
 headers: None, 
 body: Missing, 
 matching_rules: MatchingRules { 
   rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }, 
   QUERY: MatchingRuleCategory { 
     name: QUERY, 
     rules: {DocPath { 
        path_tokens: [Root, Field("item")], expr: "$.item" }: 
          RuleList { rules: [Time("HH:mm:ss")], 
     rule_logic: And, cascaded: false }} }} }, 
     generators: Generators { categories: {} } }, 
response: HttpResponse { status: 200, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"namespace1": Object {"name1": String("value1")}, "namespace2": Object {"name2": String("value2")}, "pactRust": Object {"ffi": String("0.4.25")}}, plugin_data: [] }, mock_server_started: false, specification_version: V4 } }

...
----------------------------------------------------------------------------------------
       method: GET
       path: /interaction
       query: Some({"item": [Some("12:13:00")]})
       headers: Some({"accept": ["*/*"], "accept-encoding": ["gzip", "deflate"], "connection": ["keep-alive"], "host": ["127.0.0.1:4224"], "user-agent": ["xctest/23600 CFNetwork/1568.300.101 Darwin/24.2.0"], "accept-language": ["en-AU", "en;q=0.9"]})
       body: Empty
      ————————————————————————————————————————————
...

/Users/marko/Developer/pact-foundation/PactSwift/Tests/Model/InteractionQueryTests.swift:200: error: -[PactSwiftTests.InteractionQueryTests testQueryParamMatchingTime] : XCTAssertEqual failed: ("500") is not equal to ("200")
/Users/marko/Developer/pact-foundation/PactSwift/Tests/Model/InteractionQueryTests.swift:194: error: -[PactSwiftTests.InteractionQueryTests testQueryParamMatchingTime] : failed: caught error: "pactFailure([Failure: Request does not match "GET /interaction"

QueryMismatch: Unable to match ["12:13:00"] using Time("HH:mm:ss")
  Expected: ["12:13:00"]
  Actual: ["12:13:00"]
  Parameter: $.item])"
...

📄 Stack Traces

See attached query-param-time-matcher-issue.log for full standardOut: .trace log:

query-param-time-matcher-issue.log

🤝 Relationships

  • Related PRs or Issues:
@surpher surpher changed the title Using time matcher in a query parameter failing verification Matchers: Using time matcher in a query parameter failing verification Jan 28, 2025
@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Jan 29, 2025
@rholshausen
Copy link
Contributor

This is a regression (and I assume the other issues are as well).

It's applying the matcher to the collection, not the values in the collection. Note the square brackets: Unable to match ["12:13:00"] using Time("HH:mm:ss")

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