From efc54d263e7ea53c9511cf389870e790c0158bc3 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Mon, 24 Jun 2024 11:35:57 +1000 Subject: [PATCH] fix(FFI): update_provider_info was not setting the transport scheme correctly --- rust/pact_ffi/src/verifier/handle.rs | 42 ++++++++++++++++++- rust/pact_verifier/src/provider_client.rs | 3 +- rust/pact_verifier/src/verification_result.rs | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/rust/pact_ffi/src/verifier/handle.rs b/rust/pact_ffi/src/verifier/handle.rs index 186bcf43e..a6679c1d1 100644 --- a/rust/pact_ffi/src/verifier/handle.rs +++ b/rust/pact_ffi/src/verifier/handle.rs @@ -3,10 +3,10 @@ use std::sync::Arc; use itertools::Itertools; -use pact_models::prelude::HttpAuth; use serde_json::Value; use tracing::{debug, error}; +use pact_models::prelude::HttpAuth; use pact_verifier::{ConsumerVersionSelector, FilterInfo, NullRequestFilterExecutor, PactSource, ProviderInfo, ProviderTransport, PublishOptions, VerificationOptions, verify_provider_async}; use pact_verifier::callback_executors::HttpRequestProviderStateExecutor; use pact_verifier::metrics::VerificationMetrics; @@ -107,7 +107,7 @@ impl VerifierHandle { transport: scheme.clone(), port, path: if path.is_empty() { None } else { Some(path) }, - scheme: None + scheme: if scheme.is_empty() { None } else { Some(scheme.clone()) } } ] } } @@ -342,3 +342,41 @@ impl Default for VerifierHandle { Self::new() } } + +#[cfg(test)] +mod tests { + use expectest::prelude::*; + use serde_json::Value; + + use pact_models::pact::Pact; + use pact_models::PactSpecification; + use pact_models::v4::interaction::V4Interaction; + use pact_models::v4::pact::V4Pact; + use pact_models::v4::synch_http::SynchronousHttp; + use pact_verifier::PactSource; + + use crate::verifier::handle::VerifierHandle; + + #[test] + fn update_provider_info_sets_scheme_correctly() { + let mut handle = VerifierHandle::new_for_application("test", "0.0.0"); + handle.update_provider_info("Test".to_string(), "https".to_string(), "localhost".to_string(), 1234, "".to_string()); + + let interaction = SynchronousHttp { + transport: Some("https".to_string()), + .. SynchronousHttp::default() + }; + let pact = V4Pact { + interactions: vec![ interaction.boxed_v4() ], + .. V4Pact::default() + }; + handle.sources.push(PactSource::String(pact.to_json(PactSpecification::V4).unwrap().to_string())); + let status = handle.execute(); + + expect!(status).to(be_equal_to(1)); + expect!(handle.verifier_output.result).to(be_false()); + let error: Value = handle.verifier_output.errors[0].clone().1.into(); + let message = error.as_object().unwrap()["message"].as_str().unwrap(); + expect!(message).to(be_equal_to("error sending request for url (https://localhost:1234/)")); + } +} diff --git a/rust/pact_verifier/src/provider_client.rs b/rust/pact_verifier/src/provider_client.rs index ac78aaac2..55760678f 100644 --- a/rust/pact_verifier/src/provider_client.rs +++ b/rust/pact_verifier/src/provider_client.rs @@ -21,7 +21,7 @@ use pact_models::headers::parse_header; use pact_models::v4::http_parts::{HttpRequest, HttpResponse}; use reqwest::{Client, Error, RequestBuilder}; use serde_json::Value; -use tracing::{debug, info, warn}; +use tracing::{debug, info, trace, warn}; use crate::{ProviderInfo, ProviderTransport, RequestFilterExecutor, VerificationOptions}; use crate::utils::with_retries; @@ -206,6 +206,7 @@ pub async fn make_provider_request( request.clone() }; + trace!("transport = {:?}", transport); #[allow(deprecated)] let base_url = transport .map(|trans| trans.base_url(&provider.host)) diff --git a/rust/pact_verifier/src/verification_result.rs b/rust/pact_verifier/src/verification_result.rs index 2eab3de2f..501402b64 100644 --- a/rust/pact_verifier/src/verification_result.rs +++ b/rust/pact_verifier/src/verification_result.rs @@ -100,7 +100,7 @@ impl Into for VerificationExecutionResult { /// Result of performing a match. This is a reduced version of crate::MismatchResult to make /// it thread and panic boundary safe -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, PartialOrd)] pub enum VerificationMismatchResult { /// Response mismatches Mismatches {