Skip to content

Commit

Permalink
fix(pact_consumer): Pass the transport config to the plugin in the te…
Browse files Browse the repository at this point in the history
…st context under the transport_config key
  • Loading branch information
rholshausen committed Dec 13, 2024
1 parent db14c14 commit 6189c0c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rust/pact_consumer/src/builders/pact_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl StartMockServer for PactBuilder {
match _catalog_entry {
Some(entry_name) => match catalogue_manager::lookup_entry(entry_name) {
Some(entry) => if entry.entry_type == CatalogueEntryType::TRANSPORT {
PluginMockServer::start(self.build(), self.output_dir.clone(), &entry)
PluginMockServer::start(self.build(), self.output_dir.clone(), &entry, mock_server_config)
.expect("Could not start the plugin mock server")
} else {
panic!("Catalogue entry for key '{}' is not for a network transport", entry_name);
Expand Down
4 changes: 2 additions & 2 deletions rust/pact_consumer/src/builders/pact_builder_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl StartMockServer for PactBuilderAsync {
match _catalog_entry {
Some(entry_name) => match catalogue_manager::lookup_entry(entry_name) {
Some(entry) => if entry.entry_type == CatalogueEntryType::TRANSPORT {
PluginMockServer::start(self.build(), self.output_dir.clone(), &entry)
PluginMockServer::start(self.build(), self.output_dir.clone(), &entry, mock_server_config)
.expect("Could not start the plugin mock server")
} else {
panic!("Catalogue entry for key '{}' is not for a network transport", entry_name);
Expand Down Expand Up @@ -292,7 +292,7 @@ impl StartMockServerAsync for PactBuilderAsync {
match _catalog_entry {
Some(entry_name) => match catalogue_manager::lookup_entry(entry_name) {
Some(entry) => if entry.entry_type == CatalogueEntryType::TRANSPORT {
PluginMockServer::start_async(self.build(), self.output_dir.clone(), &entry).await
PluginMockServer::start_async(self.build(), self.output_dir.clone(), &entry, mock_server_config).await
.expect("Could not start the plugin mock server")
} else {
panic!("Catalogue entry for key '{}' is not for a network transport", entry_name);
Expand Down
23 changes: 18 additions & 5 deletions rust/pact_consumer/src/mock_server/plugin_mock_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use url::Url;
use pact_matching::metrics::{MetricEvent, send_metrics_async};
use pact_mock_server::matching::MatchResult;
use pact_mock_server::mock_server::MockServerMetrics;

use serde_json::Value;
use crate::mock_server::ValidatingMockServer;
use crate::util::panic_or_print_error;

Expand All @@ -41,22 +41,35 @@ impl PluginMockServer {
pub fn start(
pact: Box<dyn Pact + Send + Sync>,
output_path: Option<PathBuf>,
catalogue_entry: &CatalogueEntry
catalogue_entry: &CatalogueEntry,
mock_server_config: Option<pact_mock_server::mock_server::MockServerConfig>
) -> anyhow::Result<Box<dyn ValidatingMockServer>> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
runtime.block_on(async { PluginMockServer::start_async(pact, output_path, catalogue_entry).await })
runtime.block_on(async {
PluginMockServer::start_async(pact, output_path, catalogue_entry, mock_server_config).await
})
}

/// Start a new plugin mock server (async version). This will send the start mock server request
/// to the plugin that provides the mock server.
pub async fn start_async(
pact: Box<dyn Pact + Send + Sync>,
output_path: Option<PathBuf>,
catalogue_entry: &CatalogueEntry
catalogue_entry: &CatalogueEntry,
mock_server_config: Option<pact_mock_server::mock_server::MockServerConfig>
) -> anyhow::Result<Box<dyn ValidatingMockServer>> {
let test_context = hashmap!{};
let test_context = if let Some(mock_server_config) = mock_server_config {
hashmap!{
"transport_config".to_string() => Value::Object(mock_server_config.transport_config
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect())
}
} else {
hashmap!{}
};
let result = start_mock_server_v2(catalogue_entry, pact.boxed(), MockServerConfig {
output_path: output_path.clone(),
host_interface: None,
Expand Down

0 comments on commit 6189c0c

Please sign in to comment.