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

Create a new PactBuilder, specifying the names of the service consuming the API and the service providing it.

Create a new PactBuilder for a V4 specification Pact, specifying the names of the service consuming the API and the service providing it.

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.

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

Directly add a pre-built Interaction to our Pact. Normally it’s easier to use interaction instead of this function.

Return the Pact we’ve built.

Sets the output directory to write pact files to

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

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

Returns an iterator over the asynchronous messages in the Pact

Returns an iterator over the synchronous req/res messages in the Pact

Trait Implementations

Executes the destructor for this type. Read more

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

Calls U::from(self).

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

Wrap the input message T in a tonic::Request

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

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