Struct wiremock::MockServerBuilder [−][src]
pub struct MockServerBuilder { /* fields omitted */ }
Expand description
A builder providing a fluent API to assemble a MockServer
step-by-step.
Use MockServer::builder
to get started.
Implementations
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());
}
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());
}
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
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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