Skip to content

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

Open
@surpher

Description

@surpher

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions