diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 919a5eb29..f0c189f0c 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -130,7 +130,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -141,7 +141,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1106,7 +1106,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2452,7 +2452,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2827,7 +2827,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -3600,9 +3600,9 @@ dependencies = [ [[package]] name = "qualname" -version = "0.0.1" +version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ca141ff6dd6af1bf241aa43eac7491d69c9be5059574708495e61948ab4bac" +checksum = "5b7e17688d7e871b907a1d869d01a72e13da2f235e47edd88e003610f26ec7a8" [[package]] name = "quick-xml" @@ -4050,7 +4050,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -4116,7 +4116,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -4510,7 +4510,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -4557,7 +4557,7 @@ dependencies = [ "cfg-if", "libc", "psm", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -4744,7 +4744,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -5550,7 +5550,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -5864,9 +5864,9 @@ dependencies = [ [[package]] name = "xrust" -version = "2.2.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb2c761645855d610598e85a199f9e86f805cf6d0d526b26cfedf38582b299f" +checksum = "11e0eacb58c190372d2d26a8716969b53e72ef30e8769748c8cb989cb874a3cd" dependencies = [ "chrono", "english-numbers", diff --git a/rust/pact_verifier_cli/Cargo.toml b/rust/pact_verifier_cli/Cargo.toml index aaf35c179..83793b48c 100644 --- a/rust/pact_verifier_cli/Cargo.toml +++ b/rust/pact_verifier_cli/Cargo.toml @@ -34,7 +34,7 @@ pact_matching = { version = "2.2.0", path = "../pact_matching", default-features pact_models = { version = "1.3.16", default-features = false } pact_verifier = { version = "1.6.0", path = "../pact_verifier", default-features = false } quick-xml = { version = "0.39.2", features = ["serde", "serialize"] } -xrust = "2.0.3" +xrust = "2.4.1" regex = "1.11.1" rustls = { version = "0.23.43", default-features = false, features = ["ring", "logging", "tls12", "std"] } serde = "1.0.228" diff --git a/rust/pact_verifier_cli/src/reports/mod.rs b/rust/pact_verifier_cli/src/reports/mod.rs index e1b446ba8..629bb586b 100644 --- a/rust/pact_verifier_cli/src/reports/mod.rs +++ b/rust/pact_verifier_cli/src/reports/mod.rs @@ -21,12 +21,20 @@ mod xml; const XSLT: &str = include_str!("verification-report.xsl"); +fn missing_namespace() -> ParseError { + ParseError::MissingNameSpace { + prefix: None, + nsuri: None, + message: Some("namespace prefixes must be declared in the document".to_string()) + } +} + fn node_from_str(s: &str) -> Result { - parse(RNode::new_document(), s, Some(|_: &_| Err(ParseError::MissingNameSpace))) + parse(RNode::new_document(), s, Some(|_: &_| Err(missing_namespace()))) } fn apply_xslt(xml_str: &str, xslt: Option<&String>) -> anyhow::Result { - let doc = parse(RNode::new_document(), xml_str, Some(|_: &_| Err(ParseError::MissingNameSpace)))?; + let doc = parse(RNode::new_document(), xml_str, Some(|_: &_| Err(missing_namespace())))?; let mut s = String::new(); let xslt_doc = if let Some(xslt) = xslt { @@ -36,15 +44,15 @@ fn apply_xslt(xml_str: &str, xslt: Option<&String>) -> anyhow::Result { } else { XSLT }; - let xslt_doc = parse(RNode::new_document(), xslt_doc, Some(|_: &_| Err(ParseError::MissingNameSpace)))?; + let xslt_doc = parse(RNode::new_document(), xslt_doc, Some(|_: &_| Err(missing_namespace())))?; let mut static_context = StaticContextBuilder::new() .message(|_| Ok(())) - .fetcher(|_| Err(Error::new(ErrorKind::NotImplemented, "not implemented"))) + .external(|_| Err(Error::new(ErrorKind::NotImplemented, "not implemented"))) .parser(|_| Err::(Error::new(ErrorKind::NotImplemented, "not implemented"))) .build(); - let mut ctxt = from_document(xslt_doc, None, node_from_str, |_| Ok(String::new()))?; + let mut ctxt = from_document(xslt_doc, None, node_from_str, |_| Ok(Vec::new()))?; ctxt.context(vec![Item::Node(doc)], 0); ctxt.result_document(RNode::new_document()); let seq = ctxt.evaluate(&mut static_context)?; @@ -148,3 +156,59 @@ pub(crate) fn write_html_report( Ok(()) } + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + use std::time::Duration; + + use insta::assert_snapshot; + use pact_matching::Mismatch; + use pact_verifier::verification_result::{ + VerificationExecutionResult, VerificationInteractionResult, VerificationMismatchResult, + }; + + use super::*; + + #[test] + fn html_report_with_default_xslt() { + let mut notice = HashMap::new(); + notice.insert("text".to_string(), "This pact is being verified because it is the latest version".to_string()); + let result = VerificationExecutionResult { + result: false, + notices: vec![notice], + errors: vec![ + ( + "GET /foo returns 200".to_string(), + VerificationMismatchResult::Mismatches { + mismatches: vec![ + Mismatch::StatusMismatch { + expected: 200, + actual: 404, + mismatch: "expected 200 but was 404".to_string(), + }, + ], + interaction_id: Some("interaction-123".to_string()), + }, + ), + ], + interaction_results: vec![ + VerificationInteractionResult { + interaction_id: None, + interaction_key: None, + consumer: "My Consumer".to_string(), + provider: "My Provider".to_string(), + provider_states: vec![], + description: "request 1".to_string(), + interaction_description: "POST /bar returns 201".to_string(), + result: Ok(()), + pending: false, + duration: Duration::from_millis(15), + }, + ], + ..VerificationExecutionResult::default() + }; + let xml = xml::to_xml_string(&result, "My Provider").unwrap(); + assert_snapshot!(apply_xslt(&xml, None).unwrap()); + } +} diff --git a/rust/pact_verifier_cli/src/reports/snapshots/pact_verifier_cli__reports__tests__html_report_with_default_xslt.snap b/rust/pact_verifier_cli/src/reports/snapshots/pact_verifier_cli__reports__tests__html_report_with_default_xslt.snap new file mode 100644 index 000000000..c644858b2 --- /dev/null +++ b/rust/pact_verifier_cli/src/reports/snapshots/pact_verifier_cli__reports__tests__html_report_with_default_xslt.snap @@ -0,0 +1,426 @@ +--- +source: pact_verifier_cli/src/reports/mod.rs +expression: "apply_xslt(&xml, None).unwrap()" +--- + +Pact Verification Report — My Provider
Pact · Verification Report

My Provider

Provider Contract Verification

✗
Failed

Summary

1
Total
1
Passed
1
Failed
0
Pending

Notices

ℹThis pact is being verified because it is the latest version

Failures

FailureGET /foo returns 200
TypeLocationDescriptionExpectedActual
Statusexpected 200 but was 404200404

Interaction Results

InteractionStatusDuration
POST /bar returns 201✓ Passed15 ms