Skip to content

Commit

Permalink
fix(FFI): update_provider_info was not setting the transport scheme c…
Browse files Browse the repository at this point in the history
…orrectly
  • Loading branch information
rholshausen committed Jun 24, 2024
1 parent 45914c0 commit efc54d2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
42 changes: 40 additions & 2 deletions rust/pact_ffi/src/verifier/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) }
} ]
}
}
Expand Down Expand Up @@ -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/)"));
}
}
3 changes: 2 additions & 1 deletion rust/pact_verifier/src/provider_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,6 +206,7 @@ pub async fn make_provider_request<F: RequestFilterExecutor>(
request.clone()
};

trace!("transport = {:?}", transport);
#[allow(deprecated)]
let base_url = transport
.map(|trans| trans.base_url(&provider.host))
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier/src/verification_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Into<Value> 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 {
Expand Down

0 comments on commit efc54d2

Please sign in to comment.