diff --git a/rust/pact_matching/src/models/mod.rs b/rust/pact_matching/src/models/mod.rs index 99e449b03..3eac5714d 100644 --- a/rust/pact_matching/src/models/mod.rs +++ b/rust/pact_matching/src/models/mod.rs @@ -96,7 +96,7 @@ impl PactSpecification { } /// Struct that defines the consumer of the pact. -#[derive(Debug, Clone, Default, Deserialize, Serialize)] +#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)] pub struct Consumer { /// Each consumer should have a unique name to identify it. pub name: String @@ -122,7 +122,7 @@ impl Consumer { } /// Struct that defines a provider of a pact. -#[derive(Debug, Clone, Default, Deserialize, Serialize)] +#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)] pub struct Provider { /// Each provider should have a unique name to identify it. pub name: String @@ -1227,7 +1227,7 @@ pub mod message_pact; pub mod v4; /// Struct that represents a pact between the consumer and provider of a service. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct RequestResponsePact { /// Consumer side of the pact pub consumer: Consumer, @@ -1486,7 +1486,7 @@ impl ReadWritePact for RequestResponsePact { .map(|either| match either { Left(i) => i, Right(i) => i, - Both(i, _) => i + Both(_, i) => i }) .cloned() .collect(), diff --git a/rust/pact_matching/src/models/tests.rs b/rust/pact_matching/src/models/tests.rs index c16d0140d..0e8488772 100644 --- a/rust/pact_matching/src/models/tests.rs +++ b/rust/pact_matching/src/models/tests.rs @@ -1950,3 +1950,43 @@ fn write_pact_test_with_generators() { }} }}"#, super::VERSION.unwrap()))); } + +#[test] +fn merge_pact_test() { + let pact = RequestResponsePact { + interactions: vec![ + RequestResponseInteraction { + description: s!("Test Interaction with matcher"), + request: Request { + body: OptionalBody::Present(json!({ "related": [1, 2, 3] }).to_string().as_bytes().to_vec(), Some(JSON.clone())), + matching_rules: matchingrules!{ + "body" => { + "$.related" => [ MatchingRule::MinMaxType(0, 5) ] + } + }, + .. Request::default() + }, + .. RequestResponseInteraction::default() + } + ], + .. RequestResponsePact::default() }; + let updated_pact = RequestResponsePact { + interactions: vec![ + RequestResponseInteraction { + description: s!("Test Interaction with matcher"), + request: Request { + body: OptionalBody::Present(json!({ "related": [1, 2, 3] }).to_string().as_bytes().to_vec(), Some(JSON.clone())), + matching_rules: matchingrules!{ + "body" => { + "$.related" => [ MatchingRule::MinMaxType(1, 10) ] + } + }, + .. Request::default() + }, + .. RequestResponseInteraction::default() + } + ], + .. RequestResponsePact::default() }; + let merged_pact = pact.merge(&updated_pact); + expect(merged_pact).to(be_ok().value(updated_pact)); +}