Skip to content

Commit

Permalink
chore: Upgrade pact_models to 1.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jul 10, 2023
1 parent c78ea50 commit 1deca59
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 45 deletions.
2 changes: 1 addition & 1 deletion rust/pact_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_consumer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 4 additions & 8 deletions rust/pact_ffi/src/mock_server/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_matching/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 6 additions & 28 deletions rust/pact_matching/src/binary_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() ||
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_mock_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_mock_server_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions rust/pact_models/src/content_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ impl From<&str> for ContentType {

impl From<Mime> 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(),
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down

0 comments on commit 1deca59

Please sign in to comment.