Skip to content

Commit

Permalink
fix: when merging pacts, it helps to use the new interations in the m…
Browse files Browse the repository at this point in the history
…erged pact, not the old ones #77
  • Loading branch information
Ronald Holshausen committed Oct 17, 2020
1 parent 2d945bf commit 3acf437
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rust/pact_matching/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
40 changes: 40 additions & 0 deletions rust/pact_matching/src/models/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 3acf437

Please sign in to comment.