I’ve been making good progress writing our own C++...
# pact-plugins
f
I’ve been making good progress writing our own C++ wrapper for the pactffi interface, but I’m stumped on how transport configs are supposed to be passed to the plugin when starting the mock server. Digging through the rust code, I have the feeling this isn’t fully implemented yet? https://github.com/pact-foundation/pact-reference/blob/74df5d1d3c55856c0b1a37a132e[…]65d1fd/rust/pact_consumer/src/mock_server/plugin_mock_server.rs
Copy code
/// 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
  ) -> anyhow::Result<Box<dyn ValidatingMockServer>> {
    let test_context = hashmap!{};
    let result = start_mock_server_v2(catalogue_entry, pact.boxed(), MockServerConfig {
      output_path: output_path.clone(),
      host_interface: None,
      port: 0,
      tls: false
    }, test_context).await?;
    Ok(Box::new(PluginMockServer {
      mock_server_details: result,
      pact: pact.boxed(),
      output_path: output_path.clone(),
      catalogue_entry: catalogue_entry.clone()
    }))
  }
It looks like the test_context isn’t hooked up yet to receive the value from the call to
pactffi_create_mock_server_for_transport
?
r
Yes, sorry about that. There are some gaps.
Let me look into that, it shouldn't be a lot of work to fix.
So there is two types of data required here: transport config (like for TLS you need the cert and cert password), and then test context data (which is needed for some cases, like injecting values from provider state callbacks).
Which are you needing to set? I'm assuming the latter. The reason it is not currently implemented is there is no way to pass this data via the FFI calls.
This will need a change to the FFI functions.
Hmm, actually, the only data used there is the mock server host and port, which the mock server adds itself. What data do you need to pass to the plugin?
Do you need something injected in the mock server response? That's the only thing I can think of.
f
So I’m looking for the transport config I guess, my plugin implements a custom transport for our proprietary messaging system. Because the plugin is running out of process, I’m using a bidirectional gRPC stream to relay messages to/from the messaging system. When starting the mock server in the plugin I’d like to be able to tell the plugin what address and port the relay server is on.
For now I’m just hard-coding it and it isn’t a big deal, but especially the port I’d like to let the server assign any available port and pass it via the transport config to the plugin
r
Ah! That's a bigger problem to address, there is no field on the
StartMockServerRequest
message to pass that data. That requires a change to that interface. I have written a proposal to fix some of the plugin interface problems, if you want to raise any issues you are having there? See https://github.com/pact-foundation/pact-plugins/blob/main/docs/proposals/001_V2_Plugin_Interface.md
So, in the short term, we could pass it through in the
test_context
field, maybe under a
transport_config
key?
f
That would work for us yeah, I’ll take a look at the draft and see if I can give input (probably in the new year after I get back from leave). Thanks 👍
r
Actually, adding a new field to that message may not be a breaking change. I'll have a look, but it mat affect code across Pact language implementations.
I think this will do what you need
f
Nice! Thanks a lot! I’ll figure out how to try out these changes once I’m back from leave
FYI I’ve updated our pactffi binaries and I can confirm it works for what I needed applause thankyou