Skip to content

Commit

Permalink
feat(verifier): Add the verifier version to the published results #307
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Feb 18, 2024
1 parent b6a0e66 commit 6962fce
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 27 deletions.
2 changes: 2 additions & 0 deletions rust/pact_verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub mod metrics;
pub mod verification_result;
mod utils;

const VERIFIER_VERSION: &str = env!("CARGO_PKG_VERSION");

/// Source for loading pacts
#[derive(Debug, Clone)]
pub enum PactSource {
Expand Down
54 changes: 32 additions & 22 deletions rust/pact_verifier/src/pact_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use tracing::{debug, error, info, trace, warn};
use pact_matching::Mismatch;

use crate::MismatchResult;
use crate::VERIFIER_VERSION;
use crate::utils::with_retries;

fn is_true(object: &serde_json::Map<String, Value>, field: &str) -> bool {
Expand Down Expand Up @@ -820,7 +821,8 @@ fn build_payload(result: TestResult, version: String, build_url: Option<String>)
"providerApplicationVersion": version,
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
});
let json_obj = json.as_object_mut().unwrap();
Expand Down Expand Up @@ -1082,6 +1084,7 @@ mod tests {
use pact_models::{Consumer, PactSpecification, Provider};
use pact_models::prelude::RequestResponsePact;
use pact_models::sync_interaction::RequestResponseInteraction;
use pretty_assertions::assert_eq;

use pact_consumer::*;
use pact_consumer::prelude::*;
Expand Down Expand Up @@ -2019,38 +2022,40 @@ mod tests {
fn test_build_payload_with_success() {
let result = TestResult::Ok(vec![]);
let payload = super::build_payload(result, "1".to_string(), None);
expect!(payload).to(be_equal_to(json!({
assert_eq!(payload, json!({
"providerApplicationVersion": "1",
"success": true,
"testResults": [],
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
})));
}));
}

#[test]
fn test_build_payload_adds_the_build_url_if_provided() {
let result = TestResult::Ok(vec![]);
let payload = super::build_payload(result, "1".to_string(), Some("http://build-url".to_string()));
expect!(payload).to(be_equal_to(json!({
assert_eq!(payload, json!({
"providerApplicationVersion": "1",
"success": true,
"buildUrl": "http://build-url",
"testResults": [],
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
})));
}));
}

#[test]
fn test_build_payload_adds_a_result_for_each_interaction() {
let result = TestResult::Ok(vec![Some("1".to_string()), Some("2".to_string()), Some("3".to_string()), None]);
let payload = super::build_payload(result, "1".to_string(), Some("http://build-url".to_string()));
expect!(payload).to(be_equal_to(json!({
assert_eq!(payload, json!({
"providerApplicationVersion": "1",
"success": true,
"buildUrl": "http://build-url",
Expand All @@ -2061,24 +2066,26 @@ mod tests {
],
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
})));
}));
}

#[test]
fn test_build_payload_with_failure() {
let result = TestResult::Failed(vec![]);
let payload = super::build_payload(result, "1".to_string(), None);
expect!(payload).to(be_equal_to(json!({
assert_eq!(payload, json!({
"providerApplicationVersion": "1",
"success": false,
"testResults": [],
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
})));
}));
}

#[test]
Expand All @@ -2094,7 +2101,7 @@ mod tests {
}))
]);
let payload = super::build_payload(result, "1".to_string(), None);
expect!(payload).to(be_equal_to(json!({
assert_eq!(payload, json!({
"providerApplicationVersion": "1",
"success": false,
"testResults": [
Expand All @@ -2110,9 +2117,10 @@ mod tests {
],
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
})));
}));
}

#[test]
Expand All @@ -2121,7 +2129,7 @@ mod tests {
(Some("1234abc".to_string()), Some(MismatchResult::Error("Bang".to_string(), Some("1234abc".to_string()))))
]);
let payload = super::build_payload(result, "1".to_string(), None);
expect!(payload).to(be_equal_to(json!({
assert_eq!(payload, json!({
"providerApplicationVersion": "1",
"success": false,
"testResults": [
Expand All @@ -2137,9 +2145,10 @@ mod tests {
],
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
})));
}));
}

#[test]
Expand All @@ -2157,7 +2166,7 @@ mod tests {
(Some("abc123".to_string()), None)
]);
let payload = super::build_payload(result, "1".to_string(), None);
expect!(payload).to(be_equal_to(json!({
assert_eq!(payload, json!({
"providerApplicationVersion": "1",
"success": false,
"testResults": [
Expand Down Expand Up @@ -2186,9 +2195,10 @@ mod tests {
],
"verifiedBy": {
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
}
})));
}));
}

#[test]
Expand Down
10 changes: 8 additions & 2 deletions rust/pact_verifier/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{NullRequestFilterExecutor, PactSource, ProviderInfo, ProviderStateEx
use crate::callback_executors::HttpRequestProviderStateExecutor;
use crate::pact_broker::Link;
use crate::verification_result::VerificationInteractionResult;
use crate::VERIFIER_VERSION;

use super::{execute_state_change, filter_consumers, filter_interaction, FilterInfo};

Expand Down Expand Up @@ -293,7 +294,8 @@ async fn publish_successful_result_to_broker() {
],
"verifiedBy": json!({
"implementation": "Pact-Rust",
"version": PACT_RUST_VERSION
"version": PACT_RUST_VERSION,
"verifierVersion": VERIFIER_VERSION
})
}));
i.response.status(201);
Expand Down Expand Up @@ -997,7 +999,11 @@ async fn test_publish_results_from_url_source_with_provider_branch() {
"providerApplicationVersion": "1.2.3",
"success": true,
"testResults": [],
"verifiedBy": { "implementation": "Pact-Rust", "version": like!("0.4.5") }
"verifiedBy": {
"implementation": "Pact-Rust",
"version": like!("0.4.5"),
"verifierVersion": like!("1.0.6")
}
}));

i.response
Expand Down
18 changes: 15 additions & 3 deletions rust/pact_verifier/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,11 @@ async fn verify_multiple_pacts() {
"success": false
}
],
"verifiedBy": { "implementation": "Pact-Rust", "version": like!("1.0.0") }
"verifiedBy": {
"implementation": "Pact-Rust",
"version": like!("1.0.0"),
"verifierVersion": like!("1.0.6")
}
}));
i
})
Expand All @@ -468,7 +472,11 @@ async fn verify_multiple_pacts() {
"success": false
}
],
"verifiedBy":{ "implementation": "Pact-Rust", "version": like!("1.0.0") }
"verifiedBy":{
"implementation": "Pact-Rust",
"version": like!("1.0.0"),
"verifierVersion": like!("1.0.6")
}
}));
i
})
Expand Down Expand Up @@ -661,7 +669,11 @@ async fn verify_message_pact_with_two_interactions() {
"success": false
}
],
"verifiedBy": { "implementation": "Pact-Rust", "version": like!("1.0.0") }
"verifiedBy": {
"implementation": "Pact-Rust",
"version": like!("1.0.0"),
"verifierVersion": like!("1.0.6")
}
}));
i
})
Expand Down

0 comments on commit 6962fce

Please sign in to comment.