pub struct MockServerBuilder { /* private fields */ }
Expand description

A builder providing a fluent API to assemble a MockServer step-by-step.
Use MockServer::builder to get started.

Implementations§

source§

impl MockServerBuilder

source

pub fn listener(self, listener: TcpListener) -> Self

Each instance of MockServer is, by default, running on a random port available on your local machine. With MockServerBuilder::listener you can choose to start the MockServer instance on a specific port you have already bound.

§Example:
use wiremock::MockServer;

#[async_std::main]
async fn main() {
    // Arrange
    let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
    let expected_server_address = listener
        .local_addr()
        .expect("Failed to get server address.");

    // Act
    let mock_server = MockServer::builder().listener(listener).start().await;

    // Assert
    assert_eq!(&expected_server_address, mock_server.address());
}
source

pub fn disable_request_recording(self) -> Self

By default, MockServer will record all incoming requests to display more meaningful error messages when your expectations are not verified.

This can sometimes be undesirable (e.g. a long-lived server serving high volumes of traffic) - you can disable request recording using MockServerBuilder::disable_request_recording.

§Example (Request recording disabled):
use wiremock::MockServer;

#[async_std::main]
async fn main() {
    // Arrange
    let mock_server = MockServer::builder().disable_request_recording().start().await;

    // Act
    let received_requests = mock_server.received_requests().await;
     
    // Assert
    assert!(received_requests.is_none());
}
source

pub fn body_print_limit(self, limit: BodyPrintLimit) -> Self

The mock server prints the requests it received when one or more mocks have expectations that have not been satisfied. By default, the size of the printed body is limited.

You may want to change this if you’re working with services with very large bodies, or when printing wiremock output to a file where size matters less than in a terminal window. You can configure this limit with MockServerBuilder::body_print_limit.

source

pub async fn start(self) -> MockServer

Finalise the builder and launch the MockServer instance!

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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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