diff --git a/rust/pact_consumer/src/builders/pact_builder.rs b/rust/pact_consumer/src/builders/pact_builder.rs index 778be08f..9754ae49 100644 --- a/rust/pact_consumer/src/builders/pact_builder.rs +++ b/rust/pact_consumer/src/builders/pact_builder.rs @@ -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); diff --git a/rust/pact_consumer/src/builders/pact_builder_async.rs b/rust/pact_consumer/src/builders/pact_builder_async.rs index a1142dbc..57eb824f 100644 --- a/rust/pact_consumer/src/builders/pact_builder_async.rs +++ b/rust/pact_consumer/src/builders/pact_builder_async.rs @@ -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); @@ -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); diff --git a/rust/pact_consumer/src/mock_server/plugin_mock_server.rs b/rust/pact_consumer/src/mock_server/plugin_mock_server.rs index 62c4a0b6..4d99cb6c 100644 --- a/rust/pact_consumer/src/mock_server/plugin_mock_server.rs +++ b/rust/pact_consumer/src/mock_server/plugin_mock_server.rs @@ -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; @@ -41,12 +41,15 @@ impl PluginMockServer { pub fn start( pact: Box, output_path: Option, - catalogue_entry: &CatalogueEntry + catalogue_entry: &CatalogueEntry, + mock_server_config: Option ) -> anyhow::Result> { 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 @@ -54,9 +57,19 @@ impl PluginMockServer { pub async fn start_async( pact: Box, output_path: Option, - catalogue_entry: &CatalogueEntry + catalogue_entry: &CatalogueEntry, + mock_server_config: Option ) -> anyhow::Result> { - 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,