Struct pact_consumer::builders::PactBuilderAsync
source · pub struct PactBuilderAsync { /* private fields */ }
Expand description
Builder for Pact
objects (async version).
use pact_consumer::prelude::*;
use pact_consumer::*;
let pact = PactBuilderAsync::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§
source§impl PactBuilderAsync
impl PactBuilderAsync
sourcepub fn new<C, P>(consumer: C, provider: P) -> Self
pub fn new<C, P>(consumer: C, provider: P) -> Self
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
pub fn new_v4<C, P>(consumer: C, provider: P) -> Self
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. This requires the plugins feature.
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 Selfwhere
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 Selfwhere
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 Selfwhere
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 Selfwhere
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 Selfwhere
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 Selfwhere
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§
source§impl Debug for PactBuilderAsync
impl Debug for PactBuilderAsync
source§impl Drop for PactBuilderAsync
impl Drop for PactBuilderAsync
source§impl StartMockServer for PactBuilderAsync
impl StartMockServer for PactBuilderAsync
source§fn start_mock_server(
&self,
_catalog_entry: Option<&str>,
) -> Box<dyn ValidatingMockServer>
fn start_mock_server( &self, _catalog_entry: Option<&str>, ) -> Box<dyn ValidatingMockServer>
source§impl StartMockServerAsync for PactBuilderAsync
impl StartMockServerAsync for PactBuilderAsync
source§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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for PactBuilderAsync
impl !RefUnwindSafe for PactBuilderAsync
impl Send for PactBuilderAsync
impl Sync for PactBuilderAsync
impl Unpin for PactBuilderAsync
impl !UnwindSafe for PactBuilderAsync
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request