diff --git a/rust/pact_cli/Cargo.toml b/rust/pact_cli/Cargo.toml index 88bd03466..e23ff6841 100644 --- a/rust/pact_cli/Cargo.toml +++ b/rust/pact_cli/Cargo.toml @@ -17,7 +17,7 @@ exclude = [ clap = "2.31.2" serde_json = "1.0" serde = "1.0" -pact_models = "~1.1.7" +pact_models = "~1.1.8" pact_matching = { version = "~1.1.1", path = "../pact_matching" } anyhow = "1.0.40" log = "0.4.14" diff --git a/rust/pact_consumer/Cargo.toml b/rust/pact_consumer/Cargo.toml index 3e3b4bad3..46e914a0b 100644 --- a/rust/pact_consumer/Cargo.toml +++ b/rust/pact_consumer/Cargo.toml @@ -14,7 +14,7 @@ exclude = [ ] [dependencies] -pact_models = "~1.1.7" +pact_models = "~1.1.8" pact_matching = { version = "~1.1.0", path = "../pact_matching" } pact_mock_server = { version = "~1.2.0", path = "../pact_mock_server" } maplit = "1.0.2" diff --git a/rust/pact_ffi/Cargo.toml b/rust/pact_ffi/Cargo.toml index 9ba2d70e3..4bfdaee45 100644 --- a/rust/pact_ffi/Cargo.toml +++ b/rust/pact_ffi/Cargo.toml @@ -17,7 +17,7 @@ exclude = [ ansi_term = "0.12.1" anyhow = "1.0.70" pact_matching = { version = "~1.1.0", path = "../pact_matching" } -pact_models = "~1.1.7" +pact_models = "~1.1.8" pact_mock_server = { version = "~1.2.0", path = "../pact_mock_server" } pact_verifier = { version = "~1.0.0", path = "../pact_verifier" } libc = "0.2.141" diff --git a/rust/pact_ffi/src/mock_server/bodies.rs b/rust/pact_ffi/src/mock_server/bodies.rs index 79cfa8e00..1a9bed673 100644 --- a/rust/pact_ffi/src/mock_server/bodies.rs +++ b/rust/pact_ffi/src/mock_server/bodies.rs @@ -473,8 +473,7 @@ mod test { } // Issue #299 - // #[test_log::test] - // TODO: Uncomment when pact_models 1.1.8 released + #[test_log::test] fn process_object_with_each_value_matcher_on_object() { let json = json!({ "pact:matcher:type": "each-value", @@ -493,21 +492,18 @@ mod test { &mut generators, DocPath::root(), false); expect!(result).to(be_equal_to(json!({ - "name": "APL", "price": 1.23 }))); expect!(matching_rules).to(be_equal_to(matchingrules_list!{ "body"; - "$" => [ MatchingRule::Type ], - "$.name" => [ MatchingRule::Type ], - "$.price" => [ MatchingRule::Decimal ] + "$" => [ MatchingRule::EachValue(MatchingRuleDefinition::new("{\"price\":1.23}".to_string(), + ValueType::Unknown, MatchingRule::Decimal, None)) ] })); expect!(generators).to(be_equal_to(Generators::default())); } // Issue #299 - // #[test_log::test] - // TODO: Uncomment when pact_models 1.1.8 released + #[test_log::test] fn process_object_with_each_key_matcher_on_object() { let json = json!({ "pact:matcher:type": "each-key", diff --git a/rust/pact_matching/Cargo.toml b/rust/pact_matching/Cargo.toml index 376c1a192..629c64e47 100644 --- a/rust/pact_matching/Cargo.toml +++ b/rust/pact_matching/Cargo.toml @@ -33,7 +33,7 @@ mime = "0.3.17" multer = { version = "2.1.0", features = ["all"] } nom = "7.1.3" onig = { version = "6.4.0", default-features = false } -pact_models = "~1.1.7" +pact_models = "~1.1.8" pact-plugin-driver = "~0.4.4" rand = "0.8.5" semver = "1.0.17" diff --git a/rust/pact_matching/src/binary_utils.rs b/rust/pact_matching/src/binary_utils.rs index 9ecadfcee..7c28743c9 100644 --- a/rust/pact_matching/src/binary_utils.rs +++ b/rust/pact_matching/src/binary_utils.rs @@ -19,7 +19,7 @@ use pact_models::bodies::OptionalBody; use pact_models::content_types::{ContentType, detect_content_type_from_bytes}; use pact_models::http_parts::HttpPart; use pact_models::matchingrules::{MatchingRule, RuleLogic}; -use pact_models::path_exp::{DocPath, PathToken}; +use pact_models::path_exp::DocPath; use pact_models::v4::http_parts::HttpRequest; use serde_json::Value; use tracing::{debug, error, warn}; @@ -446,8 +446,7 @@ pub(crate) fn match_headers( let expected_value_bin = expected_value.as_bytes(); let expected_value_str = String::from_utf8_lossy(expected_value_bin).to_string(); - // TODO: Replace with DocPath::last_field when pact_models 1.1.8 released - let part_name = last_field(path).unwrap_or("unknown part"); + let part_name = path.last_field().unwrap_or("unknown part"); if let Some(actual_value) = actual.get(key) { let actual_value_bin = actual_value.as_bytes(); @@ -494,16 +493,6 @@ pub(crate) fn match_headers( } } -// TODO: Replace with DocPath::last_field when pact_models 1.1.8 released -fn last_field(path: &DocPath) -> Option<&str> { - for token in path.tokens().iter().rev() { - if let PathToken::Field(ref field) = token { - return Some(field); - } - } - return None; -} - fn first(bytes: &[u8], len: usize) -> &[u8] { if bytes.len() <= len { bytes @@ -584,21 +573,10 @@ async fn match_file_part( debug!("Actual part headers: {:?}", actual.headers); debug!("Actual part body: [{:?}]", actual.data); - // TODO: Replace with ContentType::from(mime) when pact_models 1.1.8 is released - let expected_content_type = expected.content_type.as_ref().map(|mime| ContentType { - main_type: mime.type_().to_string(), - sub_type: mime.subtype().to_string(), - attributes: mime.params().map(|(key, value)| (key.to_string(), value.to_string())).collect(), - suffix: mime.suffix().map(|name| name.to_string()), - .. ContentType::default() - }). unwrap_or_default(); - let actual_content_type = actual.content_type.as_ref().map(|mime| ContentType { - main_type: mime.type_().to_string(), - sub_type: mime.subtype().to_string(), - attributes: mime.params().map(|(key, value)| (key.to_string(), value.to_string())).collect(), - suffix: mime.suffix().map(|name| name.to_string()), - .. ContentType::default() - }). unwrap_or_default(); + let expected_content_type = expected.content_type.clone() + .map(|mime| ContentType::from(mime)).unwrap_or_default(); + let actual_content_type = actual.content_type.clone() + .map(|mime| ContentType::from(mime)). unwrap_or_default(); debug!("Comparing mime part '{}': {} -> {}", part_name, expected_content_type, actual_content_type); let matcher_result = if expected_content_type.is_unknown() || actual_content_type.is_unknown() || diff --git a/rust/pact_mock_server/Cargo.toml b/rust/pact_mock_server/Cargo.toml index 37ebcbbc2..a0514ab0c 100644 --- a/rust/pact_mock_server/Cargo.toml +++ b/rust/pact_mock_server/Cargo.toml @@ -18,7 +18,7 @@ anyhow = "1.0.70" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.95" pact_matching = { version = "~1.1.0", path = "../pact_matching" } -pact_models = "~1.1.7" +pact_models = "~1.1.8" maplit = "1.0.2" lazy_static = "1.4.0" uuid = { version = "1.3.0", features = ["v4"] } diff --git a/rust/pact_mock_server_cli/Cargo.toml b/rust/pact_mock_server_cli/Cargo.toml index d6bf67bcc..0ae9c23f7 100644 --- a/rust/pact_mock_server_cli/Cargo.toml +++ b/rust/pact_mock_server_cli/Cargo.toml @@ -23,7 +23,7 @@ maplit = "1.0.2" itertools = "0.10.5" log = "0.4.18" lazy_static = "1.4.0" -pact_models = "~1.1.7" +pact_models = "~1.1.8" pact_matching = { version = "~1.1.0", path = "../pact_matching" } pact_mock_server = { version = "~1.2.0", path = "../pact_mock_server" } rand = "0.8.5" diff --git a/rust/pact_models/src/content_types.rs b/rust/pact_models/src/content_types.rs index b0bad05a5..1f781ed60 100644 --- a/rust/pact_models/src/content_types.rs +++ b/rust/pact_models/src/content_types.rs @@ -209,6 +209,12 @@ impl From<&str> for ContentType { impl From for ContentType { fn from(mime: Mime) -> Self { + Self::from(&mime) + } +} + +impl From<&Mime> for ContentType { + fn from(mime: &Mime) -> Self { ContentType { main_type: mime.type_().to_string(), sub_type: mime.subtype().to_string(), diff --git a/rust/pact_verifier/Cargo.toml b/rust/pact_verifier/Cargo.toml index b52bfea07..ea830bec6 100644 --- a/rust/pact_verifier/Cargo.toml +++ b/rust/pact_verifier/Cargo.toml @@ -19,7 +19,7 @@ anyhow = "1.0.66" serde = "1.0.147" serde_json = "1.0.87" pact_matching = { version = "~1.1.0", path = "../pact_matching" } -pact_models = "~1.1.7" +pact_models = "~1.1.8" pact-plugin-driver = "~0.4.4" maplit = "1.0.2" lazy_static = "1.4.0" diff --git a/rust/pact_verifier_cli/Cargo.toml b/rust/pact_verifier_cli/Cargo.toml index e165b3cb0..3a02ecfe5 100644 --- a/rust/pact_verifier_cli/Cargo.toml +++ b/rust/pact_verifier_cli/Cargo.toml @@ -14,7 +14,7 @@ exclude = [ ] [dependencies] -pact_models = "~1.1.7" +pact_models = "~1.1.8" pact_verifier = { version = "~1.0.0", path = "../pact_verifier" } tokio = { version = "1.27.0", features = ["full"] } reqwest = { version = "0.11.16", default-features = false, features = ["rustls-tls-native-roots", "blocking", "json"] } diff --git a/rust/pact_wasm/Cargo.toml b/rust/pact_wasm/Cargo.toml index 57fcfa4e9..44fffc7d1 100644 --- a/rust/pact_wasm/Cargo.toml +++ b/rust/pact_wasm/Cargo.toml @@ -18,7 +18,7 @@ exclude = [ crate-type = ["cdylib", "rlib"] [dependencies] -pact_models = "~1.1.7" +pact_models = "~1.1.8" wasm-bindgen = "0.2.79" console_error_panic_hook = "0.1.7" console_log = { version = "0.2.0", features = ["color"] }