Struct pact_consumer::builders::PactBuilder
source · [−]pub struct PactBuilder { /* private fields */ }
Expand description
Builder for Pact
objects.
use pact_consumer::prelude::*;
use pact_consumer::*;
let pact = PactBuilder::new("Greeting Client", "Greeting Server")
.interaction("asks for a greeting", "", |mut i| async move {
i.request.path("/greeting/hello");
i.response
.header("Content-Type", "application/json")
.json_body(json_pattern!({ "message": "hello" }));
i
})
.await
.build();
// The request method and response status default as follows.
assert_eq!(pact.interactions()[0].as_request_response().unwrap().request.method, "GET");
assert_eq!(pact.interactions()[0].as_request_response().unwrap().response.status, 200);
Implementations
sourceimpl PactBuilder
impl PactBuilder
sourcepub fn new<C, P>(consumer: C, provider: P) -> Self where
C: Into<String>,
P: Into<String>,
pub fn new<C, P>(consumer: C, provider: P) -> Self where
C: Into<String>,
P: Into<String>,
Create a new PactBuilder
, specifying the names of the service
consuming the API and the service providing it.
sourcepub fn new_v4<C, P>(consumer: C, provider: P) -> Self where
C: Into<String>,
P: Into<String>,
pub fn new_v4<C, P>(consumer: C, provider: P) -> Self where
C: Into<String>,
P: Into<String>,
Create a new PactBuilder
for a V4 specification Pact, specifying the names of the service
consuming the API and the service providing it.
sourcepub async fn using_plugin(
&mut self,
name: &str,
version: Option<String>
) -> &mut Self
pub async fn using_plugin(
&mut self,
name: &str,
version: Option<String>
) -> &mut Self
Add a plugin to be used by the test
Panics:
Plugins only work with V4 specification pacts. This method will panic if the pact
being built is V3 format. Use PactBuilder::new_v4
to create a builder with a V4 format
pact.
sourcepub async fn interaction<D, F, O>(
&mut self,
description: D,
interaction_type: D,
build_fn: F
) -> &mut Self where
D: Into<String>,
F: FnOnce(InteractionBuilder) -> O,
O: Future<Output = InteractionBuilder> + Send,
pub async fn interaction<D, F, O>(
&mut self,
description: D,
interaction_type: D,
build_fn: F
) -> &mut Self where
D: Into<String>,
F: FnOnce(InteractionBuilder) -> O,
O: Future<Output = InteractionBuilder> + Send,
Add a new HTTP Interaction
to the Pact
. Needs to return a clone of the builder
that is passed in.
sourcepub fn push_interaction(&mut self, interaction: &dyn Interaction) -> &mut Self
pub fn push_interaction(&mut self, interaction: &dyn Interaction) -> &mut Self
Directly add a pre-built Interaction
to our Pact
. Normally it’s
easier to use interaction
instead of this function.
sourcepub fn output_dir<D: Into<PathBuf>>(&mut self, dir: D) -> &mut Self
pub fn output_dir<D: Into<PathBuf>>(&mut self, dir: D) -> &mut Self
Sets the output directory to write pact files to
sourcepub async fn message_interaction<D, F, O>(
&mut self,
description: D,
build_fn: F
) -> &mut Self where
D: Into<String>,
F: FnOnce(MessageInteractionBuilder) -> O,
O: Future<Output = MessageInteractionBuilder> + Send,
pub async fn message_interaction<D, F, O>(
&mut self,
description: D,
build_fn: F
) -> &mut Self where
D: Into<String>,
F: FnOnce(MessageInteractionBuilder) -> O,
O: Future<Output = MessageInteractionBuilder> + Send,
Add a new Asynchronous message Interaction
to the Pact
. Needs to return a clone of the builder
that is passed in.
sourcepub async fn synchronous_message_interaction<D, F, O>(
&mut self,
description: D,
build_fn: F
) -> &mut Self where
D: Into<String>,
F: FnOnce(SyncMessageInteractionBuilder) -> O,
O: Future<Output = SyncMessageInteractionBuilder> + Send,
pub async fn synchronous_message_interaction<D, F, O>(
&mut self,
description: D,
build_fn: F
) -> &mut Self where
D: Into<String>,
F: FnOnce(SyncMessageInteractionBuilder) -> O,
O: Future<Output = SyncMessageInteractionBuilder> + Send,
Add a new synchronous message Interaction
to the Pact
. Needs to return a clone of the builder
that is passed in.
sourcepub fn messages(&self) -> MessageIterator<AsynchronousMessage>
pub fn messages(&self) -> MessageIterator<AsynchronousMessage>
Returns an iterator over the asynchronous messages in the Pact
sourcepub fn synchronous_messages(&self) -> MessageIterator<SynchronousMessage>
pub fn synchronous_messages(&self) -> MessageIterator<SynchronousMessage>
Returns an iterator over the synchronous req/res messages in the Pact
Trait Implementations
sourceimpl Drop for PactBuilder
impl Drop for PactBuilder
sourceimpl StartMockServer for PactBuilder
impl StartMockServer for PactBuilder
sourcefn start_mock_server(
&self,
catalog_entry: Option<&str>
) -> Box<dyn ValidatingMockServer>
fn start_mock_server(
&self,
catalog_entry: Option<&str>
) -> Box<dyn ValidatingMockServer>
Start a mock server running in a background thread. If the catalog entry is omitted, then a standard HTTP mock server will be started. Read more
sourcefn start_mock_server_async<'life0, 'life1, 'async_trait>(
&'life0 self,
catalog_entry: Option<&'life1 str>
) -> Pin<Box<dyn Future<Output = Box<dyn ValidatingMockServer>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn start_mock_server_async<'life0, 'life1, 'async_trait>(
&'life0 self,
catalog_entry: Option<&'life1 str>
) -> Pin<Box<dyn Future<Output = Box<dyn ValidatingMockServer>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Start a mock server running in a task (requires a Tokio runtime to be already setup)
Auto Trait Implementations
impl !RefUnwindSafe for PactBuilder
impl Send for PactBuilder
impl Sync for PactBuilder
impl Unpin for PactBuilder
impl !UnwindSafe for PactBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
impl<T> Pointable for T
impl<T> Pointable for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more