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

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn build(&self) -> Box<dyn Pact + Send + Sync>

Return the Pact we’ve built.

source

pub fn output_dir<D: Into<PathBuf>>(&mut self, dir: D) -> &mut Self

Sets the output directory to write pact files to

source

pub async fn message_interaction<D, F, O>( &mut self, description: D, build_fn: F, ) -> &mut Self

Add a new Asynchronous message Interaction to the Pact. Needs to return a clone of the builder that is passed in.

source

pub async fn synchronous_message_interaction<D, F, O>( &mut self, description: D, build_fn: F, ) -> &mut Self

Add a new synchronous message Interaction to the Pact. Needs to return a clone of the builder that is passed in.

source

pub fn messages(&self) -> MessageIterator<AsynchronousMessage>

Returns an iterator over the asynchronous messages in the Pact

source

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for PactBuilderAsync

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl StartMockServer for PactBuilderAsync

source§

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.
source§

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,

Start a mock server running in a task (requires a Tokio runtime to be already setup)

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T