diff --git a/compatibility-suite/Cargo.toml b/compatibility-suite/Cargo.toml index 5f7f6f79b..4798f3b8c 100644 --- a/compatibility-suite/Cargo.toml +++ b/compatibility-suite/Cargo.toml @@ -15,7 +15,7 @@ maplit = "1.0.2" pact_consumer = { path = "../rust/pact_consumer" } pact_models = { version = "1.3.16" } pact_matching = { version = "2.0.11" } -pact_mock_server = { version = "2.2.6" } +pact_mock_server = { version = "2.2.7" } pact_verifier = { path = "../rust/pact_verifier" } regex = "1.10.2" reqwest = { version = "0.13.4", default-features = false, features = ["json"] } diff --git a/rust/Cargo.lock b/rust/Cargo.lock index a86bcedc0..b41b87cb1 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2915,7 +2915,7 @@ dependencies = [ [[package]] name = "pact_ffi" -version = "0.5.12" +version = "0.5.13" dependencies = [ "ansi_term", "anyhow", @@ -2965,7 +2965,7 @@ dependencies = [ [[package]] name = "pact_matching" -version = "2.1.0" +version = "2.2.0" dependencies = [ "ansi_term", "anyhow", @@ -3019,8 +3019,8 @@ dependencies = [ [[package]] name = "pact_mock_server" -version = "2.2.6" -source = "git+https://github.com/pact-foundation/pact-core-mock-server.git#427966c8a756585a171ddda4a2cdc8f02e88e333" +version = "2.2.7" +source = "git+https://github.com/pact-foundation/pact-core-mock-server.git#cb03341e8bb6c12163ae361a0b2e268e45b60d14" dependencies = [ "anyhow", "bytes", @@ -3049,7 +3049,7 @@ dependencies = [ [[package]] name = "pact_models" -version = "1.3.17" +version = "1.3.18" dependencies = [ "anyhow", "ariadne", @@ -3097,7 +3097,7 @@ dependencies = [ [[package]] name = "pact_verifier" -version = "1.5.0" +version = "1.6.0" dependencies = [ "ansi_term", "anyhow", @@ -3145,7 +3145,7 @@ dependencies = [ [[package]] name = "pact_verifier_cli" -version = "1.4.0" +version = "1.5.1" dependencies = [ "ansi_term", "anyhow", @@ -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" @@ -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_consumer/Cargo.toml b/rust/pact_consumer/Cargo.toml index 3d8853bde..a3cd3db75 100644 --- a/rust/pact_consumer/Cargo.toml +++ b/rust/pact_consumer/Cargo.toml @@ -28,8 +28,8 @@ async-trait = "0.1.91" bytes = "1.12.1" itertools = "0.15.0" maplit = "1.0.2" -pact_matching = { version = "2.1.0", path = "../pact_matching", default-features = false } -pact_mock_server = { version = "2.2.6", default-features = false } +pact_matching = { version = "2.2.0", path = "../pact_matching", default-features = false } +pact_mock_server = { version = "2.2.7", default-features = false } pact_models = { version = "1.3.16", default-features = false } pact-plugin-driver = { version = "1.2.3", optional = true, default-features = false } uuid = { version = "1.24.0", features = ["v4"], optional = true } diff --git a/rust/pact_ffi/CHANGELOG.md b/rust/pact_ffi/CHANGELOG.md index 5a450ef56..aff49c160 100644 --- a/rust/pact_ffi/CHANGELOG.md +++ b/rust/pact_ffi/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## [0.5.13](https://github.com/pact-foundation/pact-reference/compare/pact_ffi-v0.5.12...pact_ffi-v0.5.13) - _2026-11-13_ + +### ๐Ÿš€ Features + +- Allow the provider state change retries to be set with PACT_PROVIDER_STATE_CHANGE_RETRIES + +### ๐Ÿ› Bug Fixes + +- Apply the matchers nested under an eachValue matcher + +- _(ffi)_ Keep the plugin transport when writing via pactffi_pact_handle_write_file + +- _(ffi)_ Don't abort the host process when stderr is full + +### ๐Ÿ—๏ธ Build and CI + +- Use caret requirements between pact crates + +- Require pact_mock_server 2.2.6 + ## [0.5.12](https://github.com/pact-foundation/pact-reference/compare/pact_ffi-v0.5.11...pact_ffi-v0.5.12) - _2026-10-19_ ### ๐Ÿ› Bug Fixes diff --git a/rust/pact_ffi/Cargo.toml b/rust/pact_ffi/Cargo.toml index cd4e9a8b3..236227fc7 100644 --- a/rust/pact_ffi/Cargo.toml +++ b/rust/pact_ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pact_ffi" -version = "0.5.12" +version = "0.5.13" authors = ["Ronald Holshausen ", "Matt Fellows ", "Andrew Lilley Brinker ", "Caleb Stepanian "] edition = "2021" description = "Pact interface for foreign languages." @@ -29,11 +29,11 @@ multipart-2021 = { version = "0.19.0", default-features = false, features = ["cl onig = { version = "6.5.3", default-features = false } # FFI Inmemory sink uses the global static `LOG_BUFFER` in the pact_matching crate. This is required to be the same # version as the mock server crate -pact_matching = { version = "2.1.0", path = "../pact_matching" } -pact_mock_server = "2.2.6" +pact_matching = { version = "2.2.0", path = "../pact_matching" } +pact_mock_server = "2.2.7" pact_models = { version = "1.3.16" } pact-plugin-driver = { version = "1.2.3" } -pact_verifier = { version = "1.5.0", path = "../pact_verifier" } +pact_verifier = { version = "1.6.0", path = "../pact_verifier" } panic-message = "0.3.0" rand = "0.9.5" rand_regex = "0.18.1" diff --git a/rust/pact_ffi/src/verifier/mod.rs b/rust/pact_ffi/src/verifier/mod.rs index 8762f1dfc..c800a7efa 100644 --- a/rust/pact_ffi/src/verifier/mod.rs +++ b/rust/pact_ffi/src/verifier/mod.rs @@ -606,12 +606,64 @@ ffi_fn! { fn pactffi_verifier_execute(handle: *mut handle::VerifierHandle) -> c_int { let handle = as_mut!(handle); - handle.execute() + execute_on_verifier_thread(handle) } { EXIT_FAILURE } } +/// Stack size of the thread that runs a verification. This is the usual size of a main thread's +/// stack, which is what the verifier was written against. +const VERIFIER_STACK_SIZE: usize = 8 * 1024 * 1024; + +/// Runs the verification on a thread of its own, and waits for it. +/// +/// The verification is driven on the thread that executes it, and it needs more stack than a +/// foreign caller may have. Threads created by the Go and JVM runtimes, among others, get the +/// platform's default thread stack, which on musl is 128 KiB, and the verification overflows it. +/// Running it on a thread whose stack size we choose makes the result independent of the caller. +fn execute_on_verifier_thread(handle: &mut handle::VerifierHandle) -> c_int { + // The handle is not Send, as the results it stores hold boxed interactions. + struct HandleRef<'a>(&'a mut handle::VerifierHandle); + // SAFETY: The handle is used by one thread at a time: this thread does not touch it until the + // verifier thread has been joined. Nothing in it is tied to the thread it was created on, which + // foreign callers already rely on, as they are free to call each function from a different + // thread. + unsafe impl Send for HandleRef<'_> {} + + // The test run ID is thread local, so carry it over to the thread doing the work. + let test_run_id = pact_plugin_driver::test_context::current_test_run_id(); + + let result = std::thread::scope(|scope| { + let handle = HandleRef(&mut *handle); + let spawned = std::thread::Builder::new() + .name("pact-verifier".to_string()) + .stack_size(VERIFIER_STACK_SIZE) + .spawn_scoped(scope, move || { + // Use the wrapper as a whole, so that the closure captures it and not the field in it + let handle = handle; + pact_plugin_driver::test_context::set_test_run_id(test_run_id); + handle.0.execute() + }); + match spawned { + Ok(thread) => match thread.join() { + Ok(result) => Some(result), + // Let the panic carry on to the caller, as it would have without the thread + Err(panic) => std::panic::resume_unwind(panic) + }, + Err(err) => { + warn!("Could not start a thread to run the verification on, using the calling thread: {}", err); + None + } + } + }); + + match result { + Some(result) => result, + None => handle.execute() + } +} + fn get_vector(items_ptr: *const *const c_char, items_len: c_ushort) -> Vec { if !items_ptr.is_null() && items_len > 0 { let mut items = Vec::with_capacity(items_len as usize); @@ -734,7 +786,23 @@ mod tests { use libc::c_char; use crate::verifier::handle::VerifierHandle; - use crate::verifier::pactffi_verifier_output; + use crate::verifier::{pactffi_verifier_execute, pactffi_verifier_output}; + + // musl gives threads a 128 KiB stack by default, and that is the stack a Go or JVM caller + // will be on when it calls into the verifier. + #[test] + fn pactffi_verifier_execute_does_not_depend_on_the_callers_stack_size() { + let result = std::thread::Builder::new() + .stack_size(128 * 1024) + .spawn(|| { + let mut handle = VerifierHandle::new_for_application("tests", "1.0.0"); + pactffi_verifier_execute(&mut handle) + }) + .unwrap() + .join() + .unwrap(); + expect!(result).to(be_equal_to(0)); + } #[test] fn pactffi_verifier_output_test() { diff --git a/rust/pact_matching/CHANGELOG.md b/rust/pact_matching/CHANGELOG.md index 7c4db3784..aadbdb201 100644 --- a/rust/pact_matching/CHANGELOG.md +++ b/rust/pact_matching/CHANGELOG.md @@ -1,5 +1,47 @@ # Changelog +## [2.2.0](https://github.com/pact-foundation/pact-reference/compare/pact_matching-v2.1.0...pact_matching-v2.2.0) - _2026-11-12_ + +### ๐Ÿš€ Features + +- _(matching)_ Respect Link and Via grammars when splitting headers + +### ๐Ÿ› Bug Fixes + +- Apply the matchers nested under an eachValue matcher + +- Apply an eachValue rule once when the values already have it + +- _(pact_matching)_ Merge the eachValue rules into any existing rules for the values + +- _(v2 engine)_ Apply the rules defined below an eachValue matcher to its values + +- _(matching)_ Match combined headers against repeated expectations + +- _(matching)_ Normalize repeated custom headers across engines + +- _(matching)_ Classify headers once for both engines + +- _(matching)_ Compare repeated custom headers by their joined value + +- _(matching)_ Apply scalar header matchers to the joined value + +- _(matching)_ Split repeated headers into list elements for list matchers + +- _(matching)_ Normalise repeated headers using the header's own grammar + +- _(matching)_ Use the header grammar when comparing single header values + +- _(matching)_ Name the failing value when a repeated header fails a scalar rule + +### ๐Ÿ“š Documentation + +- _(matching)_ Describe repeated header matching + +### ๐Ÿงช Testing + +- _(matching)_ Keep separate-line header list cases beside combined ones + ## [2.1.0](https://github.com/pact-foundation/pact-reference/compare/pact_matching-v2.0.11...pact_matching-v2.1.0) - _2026-10-21_ ### ๐Ÿš€ Features diff --git a/rust/pact_matching/Cargo.toml b/rust/pact_matching/Cargo.toml index d6342f83d..64825f162 100644 --- a/rust/pact_matching/Cargo.toml +++ b/rust/pact_matching/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pact_matching" -version = "2.1.0" +version = "2.2.0" authors = ["Ronald Holshausen "] edition = "2024" description = "Pact-Rust support library that implements request and response matching logic" diff --git a/rust/pact_models/CHANGELOG.md b/rust/pact_models/CHANGELOG.md index 992dbce2c..65aa12216 100644 --- a/rust/pact_models/CHANGELOG.md +++ b/rust/pact_models/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [1.3.18](https://github.com/pact-foundation/pact-reference/compare/pact_models-v1.3.17...pact_models-v1.3.18) - _2026-11-13_ + +### ๐Ÿ“š Documentation + +- _(pact_models)_ Curate the release changelog + ## [1.3.17](https://github.com/pact-foundation/pact-reference/compare/pact_models-v1.3.16...pact_models-v1.3.17) - _2026-10-21_ ### ๐Ÿ› Bug Fixes diff --git a/rust/pact_models/Cargo.toml b/rust/pact_models/Cargo.toml index 61389d810..edda37c2c 100644 --- a/rust/pact_models/Cargo.toml +++ b/rust/pact_models/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pact_models" -version = "1.3.17" +version = "1.3.18" authors = ["Ronald Holshausen "] edition = "2024" description = "Pact-Rust support library that provides the core models for dealing with Pact files" diff --git a/rust/pact_verifier/CHANGELOG.md b/rust/pact_verifier/CHANGELOG.md index 400b583e5..1fbf7233e 100644 --- a/rust/pact_verifier/CHANGELOG.md +++ b/rust/pact_verifier/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [1.6.0](https://github.com/pact-foundation/pact-reference/compare/pact_verifier-v1.5.0...pact_verifier-v1.6.0) - _2026-11-13_ + +### ๐Ÿš€ Features + +- Allow the provider state change retries to be set with PACT_PROVIDER_STATE_CHANGE_RETRIES + +### ๐Ÿ› Bug Fixes + +- _(pact_verifier)_ Apply generators to form-urlencoded request bodies + +### ๐Ÿ“ฆ Other + +- Merge pull request #592 from ChangkeunJ/fix/verifier-form-urlencoded-generators + ## [1.5.0](https://github.com/pact-foundation/pact-reference/compare/pact_verifier-v1.4.7...pact_verifier-v1.5.0) - _2026-10-21_ ### ๐Ÿš€ Features diff --git a/rust/pact_verifier/Cargo.toml b/rust/pact_verifier/Cargo.toml index c3285890d..1c4887542 100644 --- a/rust/pact_verifier/Cargo.toml +++ b/rust/pact_verifier/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pact_verifier" -version = "1.5.0" +version = "1.6.0" authors = ["Ronald Holshausen "] edition = "2024" description = "Pact-Rust support library that implements provider verification functions" @@ -15,11 +15,12 @@ exclude = [ ] [features] -default = ["datetime", "xml", "plugins", "multipart"] +default = ["datetime", "xml", "plugins", "multipart", "form_urlencoded"] datetime = ["pact_models/datetime", "pact-plugin-driver?/datetime", "pact_matching/datetime"] # Support for date/time matchers and expressions xml = ["pact_models/xml", "pact-plugin-driver?/xml", "pact_matching/xml"] # support for matching XML documents plugins = ["dep:pact-plugin-driver", "dep:uuid", "pact_matching/plugins", "pact-plugin-driver/default"] multipart = ["pact_matching/multipart"] # suport for MIME multipart bodies +form_urlencoded = ["pact_models/form_urlencoded", "pact_matching/form_urlencoded"] # support for generating form urlencoded bodies [dependencies] ansi_term = "0.12.1" @@ -35,7 +36,7 @@ itertools = "0.15.0" lazy_static = "1.5.0" maplit = "1.0.2" mime = "0.3.17" -pact_matching = { version = "2.1.0", path = "../pact_matching", default-features = false } +pact_matching = { version = "2.2.0", path = "../pact_matching", default-features = false } pact_models = { version = "1.3.16", default-features = false } pact-plugin-driver = { version = "1.2.3", optional = true, default-features = false } uuid = { version = "1.24.0", features = ["v4"], optional = true } diff --git a/rust/pact_verifier/src/tests.rs b/rust/pact_verifier/src/tests.rs index f520190df..7ea408a06 100644 --- a/rust/pact_verifier/src/tests.rs +++ b/rust/pact_verifier/src/tests.rs @@ -16,12 +16,14 @@ use rstest::rstest; use serde_json::{json, Value}; use pact_consumer::prelude::*; use pact_models::Consumer; +use pact_models::generators::GeneratorTestMode; use pact_models::interaction::Interaction; use pact_models::pact::Pact; use pact_models::prelude::v4::SynchronousHttp; use pact_models::provider_states::*; use pact_models::sync_interaction::RequestResponseInteraction; use pact_models::sync_pact::RequestResponsePact; +use pact_models::v4::http_parts::HttpRequest; use crate::{ FilterById, @@ -1256,3 +1258,38 @@ fn process_comments_with_no_references_produces_no_references_section() { super::process_comments(&interaction, &mut output); assert_snapshot!(output.join("\n")); } + +#[test_log::test(tokio::test)] +async fn generate_request_applies_body_generators_to_a_form_urlencoded_request() { + let request = HttpRequest::from_json(&json!({ + "method": "POST", + "path": "/orders", + "headers": { "Content-Type": "application/x-www-form-urlencoded" }, + "body": { + "content": "customer=1&qty=2¬e=gift+wrap", + "contentType": "application/x-www-form-urlencoded", + "encoded": false + }, + "generators": { + "body": { + "$.customer": { "type": "ProviderState", "expression": "${customer}", "dataType": "STRING" }, + "$.qty": { "type": "RandomInt", "min": 100, "max": 999 } + } + } + })).unwrap(); + let context = hashmap!{ "customer" => json!(1234) }; + + let generated = pact_matching::generate_request(&request, &GeneratorTestMode::Provider, &context).await; + + let body = String::from_utf8(generated.body.value().unwrap().to_vec()).unwrap(); + let params: Vec<(&str, &str)> = body.split('&') + .map(|param| param.split_once('=').unwrap()) + .collect(); + expect!(params.len()).to(be_equal_to(3)); + expect!(params[0]).to(be_equal_to(("customer", "1234"))); + expect!(params[1].0).to(be_equal_to("qty")); + let qty: i32 = params[1].1.parse().unwrap(); + expect!(qty).to(be_greater_or_equal_to(100)); + expect!(qty).to(be_less_or_equal_to(999)); + expect!(params[2]).to(be_equal_to(("note", "gift+wrap"))); +} diff --git a/rust/pact_verifier_cli/CHANGELOG.md b/rust/pact_verifier_cli/CHANGELOG.md index 7a8e3cedc..3849802fc 100644 --- a/rust/pact_verifier_cli/CHANGELOG.md +++ b/rust/pact_verifier_cli/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [1.5.1](https://github.com/pact-foundation/pact-reference/compare/pact_verifier_cli-v1.5.0...pact_verifier_cli-v1.5.1) - _2026-11-23_ + +### ๐Ÿ› Bug Fixes + +- _(pact_verifier_cli)_ Build against xrust 2.4 + +### ๐Ÿงช Testing + +- _(pact_verifier_cli)_ Snapshot the HTML report + +### ๐Ÿ› ๏ธ Miscellaneous Tasks + +- _(pact_verifier_cli)_ Extract release tarball into a workdir in Docker fetch stage ([#608](https://github.com/pact-foundation/pact-reference/pull/608)) + +## [1.5.0](https://github.com/pact-foundation/pact-reference/compare/pact_verifier_cli-v1.4.0...pact_verifier_cli-v1.5.0) - _2026-11-13_ + +### ๐Ÿš€ Features + +- Allow the provider state change retries to be set with PACT_PROVIDER_STATE_CHANGE_RETRIES + +### ๐Ÿ› Bug Fixes + +- _(pact_verifier)_ Apply generators to form-urlencoded request bodies + +### ๐Ÿ“ฆ Other + +- Merge pull request #592 from ChangkeunJ/fix/verifier-form-urlencoded-generators + ## [1.4.0](https://github.com/pact-foundation/pact-reference/compare/pact_verifier_cli-v1.3.5...pact_verifier_cli-v1.4.0) - _2026-10-21_ ### ๐Ÿš€ Features diff --git a/rust/pact_verifier_cli/Cargo.toml b/rust/pact_verifier_cli/Cargo.toml index 9c95ed3c2..71309efa6 100644 --- a/rust/pact_verifier_cli/Cargo.toml +++ b/rust/pact_verifier_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pact_verifier_cli" -version = "1.4.0" +version = "1.5.1" authors = ["Ronald Holshausen "] edition = "2024" description = "Standalone pact verifier for provider pact verification" @@ -14,11 +14,12 @@ exclude = [ ] [features] -default = ["datetime", "xml", "plugins", "multipart", "junit"] +default = ["datetime", "xml", "plugins", "multipart", "form_urlencoded", "junit"] datetime = ["pact_models/datetime", "pact_verifier/datetime"] # Support for date/time matchers and expressions xml = ["pact_models/xml", "pact_verifier/xml"] # support for matching XML documents plugins = ["pact_verifier/plugins"] multipart = ["pact_verifier/multipart"] # support for MIME multipart bodies +form_urlencoded = ["pact_models/form_urlencoded", "pact_verifier/form_urlencoded"] # support for form urlencoded bodies junit = ["dep:junit-report", "dep:strip-ansi-escapes"] # support for Junit format reports [dependencies] @@ -29,11 +30,11 @@ junit-report = { version = "0.8.3", optional = true } lazy_static = "1.5.0" log = "0.4.27" maplit = "1.0.2" -pact_matching = { version = "2.1.0", path = "../pact_matching", default-features = false } +pact_matching = { version = "2.2.0", path = "../pact_matching", default-features = false } pact_models = { version = "1.3.16", default-features = false } -pact_verifier = { version = "1.5.0", path = "../pact_verifier", 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/Dockerfile b/rust/pact_verifier_cli/Dockerfile index 3625ab5f2..dfed67ab2 100644 --- a/rust/pact_verifier_cli/Dockerfile +++ b/rust/pact_verifier_cli/Dockerfile @@ -4,6 +4,7 @@ FROM --platform=$BUILDPLATFORM alpine:3.22 AS fetch ARG VERSION ARG TARGETARCH RUN apk add --no-cache ca-certificates curl xz +WORKDIR /dist RUN case "$TARGETARCH" in \ amd64) target=x86_64-unknown-linux-musl ;; \ arm64) target=aarch64-unknown-linux-musl ;; \ 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