diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 710f3426d..55b1f0983 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2200,7 +2200,7 @@ dependencies = [ [[package]] name = "pact_verifier" -version = "1.2.0" +version = "1.2.1" dependencies = [ "ansi_term", "anyhow", diff --git a/rust/pact_matching/src/lib.rs b/rust/pact_matching/src/lib.rs index 485fae4f9..e657f3e82 100644 --- a/rust/pact_matching/src/lib.rs +++ b/rust/pact_matching/src/lib.rs @@ -382,6 +382,7 @@ use pact_models::v4::message_parts::MessageContents; use pact_models::v4::sync_message::SynchronousMessage; #[cfg(feature = "plugins")] use pact_plugin_driver::catalogue_manager::find_content_matcher; #[cfg(feature = "plugins")] use pact_plugin_driver::plugin_models::PluginInteractionConfig; +use serde::__private::from_utf8_lossy; use serde_json::{json, Value}; use tracing::{debug, error, info, instrument, trace, warn}; @@ -763,9 +764,13 @@ fn match_xml( /// Store common mismatch information so it can be converted to different type of mismatches #[derive(Debug, Clone, PartialOrd, Ord, Eq)] pub struct CommonMismatch { - path: String, + /// path expression to where the mismatch occurred + pub path: String, + /// expected value (as a string) expected: String, + /// actual value (as a string) actual: String, + /// Description of the mismatch description: String } @@ -813,6 +818,61 @@ impl PartialEq for CommonMismatch { } } +impl From for CommonMismatch { + fn from(value: Mismatch) -> Self { + match value { + Mismatch::MethodMismatch { expected, actual } => CommonMismatch { + path: "".to_string(), + expected: expected.clone(), + actual: actual.clone(), + description: "Method mismatch".to_string() + }, + Mismatch::PathMismatch { expected, actual, mismatch } => CommonMismatch { + path: "".to_string(), + expected: expected.clone(), + actual: actual.clone(), + description: mismatch.clone() + }, + Mismatch::StatusMismatch { expected, actual, mismatch } => CommonMismatch { + path: "".to_string(), + expected: expected.to_string(), + actual: actual.to_string(), + description: mismatch.clone() + }, + Mismatch::QueryMismatch { parameter, expected, actual, mismatch } => CommonMismatch { + path: parameter.clone(), + expected: expected.clone(), + actual: actual.clone(), + description: mismatch.clone() + }, + Mismatch::HeaderMismatch { key, expected, actual, mismatch } => CommonMismatch { + path: key.clone(), + expected: expected.clone(), + actual: actual.clone(), + description: mismatch.clone() + }, + Mismatch::BodyTypeMismatch { expected, actual, mismatch, .. } => CommonMismatch { + path: "".to_string(), + expected: expected.clone(), + actual: actual.clone(), + description: mismatch.clone() + }, + Mismatch::BodyMismatch { path, expected, actual, mismatch } => CommonMismatch { + path: path.clone(), + expected: from_utf8_lossy(expected.unwrap_or_default().as_ref()).to_string(), + actual: from_utf8_lossy(actual.unwrap_or_default().as_ref()).to_string(), + description: mismatch.clone() + }, + Mismatch::MetadataMismatch { key, expected, actual, mismatch } => CommonMismatch { + path: key.clone(), + expected: expected.clone(), + actual: actual.clone(), + description: mismatch.clone() + } + } + } +} + /// Enum that defines the different types of mismatches that can occur. #[derive(Debug, Clone, PartialOrd, Ord, Eq)] pub enum Mismatch {