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

fix: Fix can't compare 2 eachKey matching rules, 2 eachValue matching rules #464

Conversation

tienvx
Copy link
Contributor

@tienvx tienvx commented Sep 6, 2024

Each Value

Given this test:

  #[test]
  fn each_value_matching_rule_comparation_test() {
    assert_eq!(
      matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachValue(MatchingRuleDefinition::new("[\"string value\"]".to_string(), ValueType::Unknown, MatchingRule::Type, None))]},
      matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachValue(MatchingRuleDefinition::new("[\"something else\"]".to_string(), ValueType::Unknown, MatchingRule::Type, None))]}
    )
  }

Without the fix, this test will pass

With the fix, this test will failed with:


---- mock_server::bodies::test::each_value_matching_rule_comparation_test stdout ----
thread 'mock_server::bodies::test::each_value_matching_rule_comparation_test' panicked at pact_ffi/src/mock_server/bodies.rs:1133:5:
assertion failed: `(left == right)`

Diff < left / right > :
 MatchingRuleCategory {
     name: BODY,
     rules: {
         DocPath {
             path_tokens: [
                 Root,
                 Field(
                     "array_values",
                 ),
             ],
             expr: "$.array_values",
         }: RuleList {
             rules: [
                 EachValue(
                     MatchingRuleDefinition {
<                        value: "[\"string value\"]",
>                        value: "[\"something else\"]",
                         value_type: Unknown,
                         rules: [
                             Left(
                                 Type,
                             ),
                         ],
                         generator: None,
                     },
                 ),
             ],
             rule_logic: And,
             cascaded: false,
         },
     },
 }


Each Key

Given this test:

  #[test]
  fn each_key_matching_rule_comparation_test() {
    assert_eq!(
      matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachKey(MatchingRuleDefinition::new("a_key".to_string(), ValueType::Unknown, MatchingRule::Type, None))]},
      matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachKey(MatchingRuleDefinition::new("another_key".to_string(), ValueType::Unknown, MatchingRule::Type, None))]}
    )
  }

Without this fix, the test will pass

With this fix, the test will failed with:


failures:

---- mock_server::bodies::test::each_key_matching_rule_comparation_test stdout ----
thread 'mock_server::bodies::test::each_key_matching_rule_comparation_test' panicked at pact_ffi/src/mock_server/bodies.rs:1141:5:
assertion failed: `(left == right)`

Diff < left / right > :
 MatchingRuleCategory {
     name: BODY,
     rules: {
         DocPath {
             path_tokens: [
                 Root,
                 Field(
                     "array_values",
                 ),
             ],
             expr: "$.array_values",
         }: RuleList {
             rules: [
                 EachKey(
                     MatchingRuleDefinition {
<                        value: "a_key",
>                        value: "another_key",
                         value_type: Unknown,
                         rules: [
                             Left(
                                 Type,
                             ),
                         ],
                         generator: None,
                     },
                 ),
             ],
             rule_logic: And,
             cascaded: false,
         },
     },
 }

@tienvx tienvx changed the title fix: Fix can't compare 2 eachKey matching rules, 2 eachValue matching… fix: Fix can't compare 2 eachKey matching rules, 2 eachValue matching rules Sep 6, 2024
@tienvx tienvx force-pushed the fix-cant-compare-each-key-each-value-matching-rules branch from ac0260e to 51e90e5 Compare September 6, 2024 09:03
@tienvx tienvx force-pushed the fix-cant-compare-each-key-each-value-matching-rules branch from 51e90e5 to c279376 Compare September 6, 2024 10:07
@tienvx tienvx marked this pull request as ready for review October 30, 2024 02:52
@rholshausen rholshausen merged commit f3918b6 into pact-foundation:master Nov 13, 2024
37 checks passed
@tienvx tienvx deleted the fix-cant-compare-each-key-each-value-matching-rules branch November 13, 2024 01:14
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

Successfully merging this pull request may close these issues.

2 participants