diff --git a/rust/pact_verifier/src/lib.rs b/rust/pact_verifier/src/lib.rs index d3be28b01..30d7afcb6 100644 --- a/rust/pact_verifier/src/lib.rs +++ b/rust/pact_verifier/src/lib.rs @@ -1031,6 +1031,17 @@ const VERIFICATION_NOTICE_AFTER_SUCCESSFUL_RESULT_AND_NO_PUBLISH: &str = "after_ const VERIFICATION_NOTICE_AFTER_ERROR_RESULT_AND_PUBLISH: &str = "after_verification:success_false_published_true"; const VERIFICATION_NOTICE_AFTER_ERROR_RESULT_AND_NO_PUBLISH: &str = "after_verification:success_false_published_false"; +/// The broker notice stage to display after verifying a pact, based on whether the verification +/// was successful and whether the results were published. +fn after_verification_notice_stage(success: bool, published: bool) -> &'static str { + match (success, published) { + (true, true) => VERIFICATION_NOTICE_AFTER_SUCCESSFUL_RESULT_AND_PUBLISH, + (true, false) => VERIFICATION_NOTICE_AFTER_SUCCESSFUL_RESULT_AND_NO_PUBLISH, + (false, true) => VERIFICATION_NOTICE_AFTER_ERROR_RESULT_AND_PUBLISH, + (false, false) => VERIFICATION_NOTICE_AFTER_ERROR_RESULT_AND_NO_PUBLISH + } +} + fn process_notices(context: &Option, stage: &str, result: &mut VerificationExecutionResult) { if let Some(c) = context { result.notices = c.verification_properties.notices.clone(); @@ -1181,17 +1192,11 @@ pub async fn verify_provider_async Client { Client::new() } +#[test] +fn after_verification_notice_stage_selects_the_stage_from_the_result_and_whether_it_was_published() { + expect!(super::after_verification_notice_stage(true, true)).to(be_equal_to("after_verification:success_true_published_true")); + expect!(super::after_verification_notice_stage(true, false)).to(be_equal_to("after_verification:success_true_published_false")); + expect!(super::after_verification_notice_stage(false, true)).to(be_equal_to("after_verification:success_false_published_true")); + expect!(super::after_verification_notice_stage(false, false)).to(be_equal_to("after_verification:success_false_published_false")); +} + #[test] fn if_no_interaction_filter_is_defined_returns_true() { let interaction = RequestResponseInteraction::default();