Skip to content

Commit

Permalink
fix: Upgrade pact_matching crate to 0.12.9 (fixes type matches with q…
Browse files Browse the repository at this point in the history
…uery parameters) #48
  • Loading branch information
rholshausen committed Jun 10, 2022
1 parent 62fd1ac commit d864952
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 18 deletions.
59 changes: 42 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude = [
clap = { version = "3.1.18", features = ["env"] }
serde = "1.0.137"
serde_json = "1.0.81"
pact_matching = "0.12.8"
pact_matching = "0.12.9"
pact_verifier = "0.13.7"
pact_models = "0.4.1"
maplit = "1.0.2"
Expand All @@ -40,3 +40,5 @@ quickcheck = "1.0.3"
expectest = "0.12.0"
rand = "0.8.5"
pretty_assertions = "1.2.1"
test-log = "0.2.10"
env_logger = "0.9.0"
79 changes: 79 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,85 @@ mod test {
.to(be_ok());
}

#[test_log::test(tokio::test)]
async fn match_request_with_repeated_query_params() {
let matching_rules = matchingrules!{
"query" => {
"ids" => [ MatchingRule::MinType(2) ],
"ids[*]" => [ MatchingRule::Type ]
}
};
let interaction = SynchronousHttp {
request: HttpRequest {
path: "/api".to_string(),
query: Some(hashmap!{
"ids".to_string() => vec![
"1".to_string(),
"2".to_string(),
"3".to_string(),
"4".to_string()
]
}),
matching_rules,
.. HttpRequest::default()
},
.. SynchronousHttp::default()
};

let pact = V4Pact {
interactions: vec![ interaction.boxed_v4() ],
.. V4Pact::default()
};

let request1 = HttpRequest {
path: "/api".to_string(),
query: Some(hashmap!{ "ids".to_string() => vec![ "3".to_string() ] }),
.. HttpRequest::default() };
let request2 = HttpRequest {
path: "/api".to_string(),
query: Some(hashmap!{ "ids".to_string() => vec![ "3".to_string(), "1".to_string() ] }),
.. HttpRequest::default() };
let request3 = HttpRequest {
path: "/api".to_string(),
query: Some(hashmap!{ "ids".to_string() => vec![
"1".to_string(),
"2".to_string(),
"3".to_string(),
"4".to_string()
] }),
.. HttpRequest::default() };
let request4 = HttpRequest {
path: "/api".to_string(),
query: Some(hashmap!{ "ids".to_string() => vec![
"id".to_string(),
"id".to_string(),
"id".to_string(),
"id".to_string()
] }),
.. HttpRequest::default() };
let request5 = HttpRequest {
path: "/api".to_string(),
query: Some(hashmap!{ "ids".to_string() => vec![
"1".to_string(),
"2".to_string(),
"3".to_string(),
"4".to_string(),
"5".to_string()
] }),
.. HttpRequest::default() };

expect!(super::find_matching_request(&request1, false, false, vec![pact.clone()], None, false).await)
.to(be_err());
expect!(super::find_matching_request(&request2, false, false, vec![pact.clone()], None, false).await)
.to(be_ok());
expect!(super::find_matching_request(&request3, false, false, vec![pact.clone()], None, false).await)
.to(be_ok());
expect!(super::find_matching_request(&request4, false, false, vec![pact.clone()], None, false).await)
.to(be_ok());
expect!(super::find_matching_request(&request5, false, false, vec![pact.clone()], None, false).await)
.to(be_ok());
}

#[tokio::test]
async fn match_request_filters_interactions_if_provider_state_filter_is_provided() {
let response1 = HttpResponse { status: 201, .. HttpResponse::default() };
Expand Down

0 comments on commit d864952

Please sign in to comment.