Struct wiremock::MockServerBuilder
source · [−]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
sourceimpl MockServerBuilder
impl MockServerBuilder
sourcepub fn listener(self, listener: TcpListener) -> Self
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());
}
sourcepub fn disable_request_recording(self) -> Self
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());
}
sourcepub async fn start(self) -> MockServer
pub async fn start(self) -> MockServer
Finalise the builder and launch the MockServer
instance!
Auto Trait Implementations
impl RefUnwindSafe for MockServerBuilder
impl Send for MockServerBuilder
impl Sync for MockServerBuilder
impl Unpin for MockServerBuilder
impl UnwindSafe for MockServerBuilder
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>
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