pub struct MockServerClient { /* private fields */ }Expand description
A blocking client for the MockServer control-plane REST API.
Created via ClientBuilder. All methods are synchronous.
Implementations§
Source§impl MockServerClient
impl MockServerClient
Sourcepub fn upsert(&self, expectations: &[Expectation]) -> Result<Vec<Expectation>>
pub fn upsert(&self, expectations: &[Expectation]) -> Result<Vec<Expectation>>
Create one or more expectations on the server.
Returns the created expectations as echoed by the server.
Sourcepub fn when(&self, request: HttpRequest) -> ForwardChainExpectation<'_>
pub fn when(&self, request: HttpRequest) -> ForwardChainExpectation<'_>
Begin building an expectation with the fluent when(...).respond(...) API.
§Example
use mockserver_client::{ClientBuilder, HttpRequest, HttpResponse};
let client = ClientBuilder::new("localhost", 1080).build().unwrap();
client.when(HttpRequest::new().method("GET").path("/foo"))
.respond(HttpResponse::new().status_code(200).body("bar"))
.unwrap();Sourcepub fn verify(
&self,
request: HttpRequest,
times: VerificationTimes,
) -> Result<()>
pub fn verify( &self, request: HttpRequest, times: VerificationTimes, ) -> Result<()>
Verify that a request was received the specified number of times.
Returns Ok(()) if verification passes, or
Err(Error::VerificationFailure) with the server’s failure message.
Sourcepub fn verify_sequence(&self, requests: Vec<HttpRequest>) -> Result<()>
pub fn verify_sequence(&self, requests: Vec<HttpRequest>) -> Result<()>
Verify that requests were received in the given order.
Sourcepub fn clear(
&self,
request: Option<&HttpRequest>,
clear_type: Option<ClearType>,
) -> Result<()>
pub fn clear( &self, request: Option<&HttpRequest>, clear_type: Option<ClearType>, ) -> Result<()>
Clear expectations and/or logs matching the given request.
If request is None, clears everything of the specified type.
Sourcepub fn clear_by_id(
&self,
expectation_id: impl Into<String>,
clear_type: Option<ClearType>,
) -> Result<()>
pub fn clear_by_id( &self, expectation_id: impl Into<String>, clear_type: Option<ClearType>, ) -> Result<()>
Clear expectations by expectation ID.
Sourcepub fn retrieve_recorded_requests(
&self,
request: Option<&HttpRequest>,
) -> Result<Vec<HttpRequest>>
pub fn retrieve_recorded_requests( &self, request: Option<&HttpRequest>, ) -> Result<Vec<HttpRequest>>
Retrieve recorded requests matching the optional filter.
Sourcepub fn retrieve_active_expectations(
&self,
request: Option<&HttpRequest>,
) -> Result<Vec<Expectation>>
pub fn retrieve_active_expectations( &self, request: Option<&HttpRequest>, ) -> Result<Vec<Expectation>>
Retrieve active expectations matching the optional filter.
Sourcepub fn retrieve_recorded_expectations(
&self,
request: Option<&HttpRequest>,
) -> Result<Vec<Expectation>>
pub fn retrieve_recorded_expectations( &self, request: Option<&HttpRequest>, ) -> Result<Vec<Expectation>>
Retrieve recorded expectations matching the optional filter.
Sourcepub fn retrieve_log_messages(
&self,
request: Option<&HttpRequest>,
) -> Result<Vec<String>>
pub fn retrieve_log_messages( &self, request: Option<&HttpRequest>, ) -> Result<Vec<String>>
Retrieve log messages matching the optional filter.
Sourcepub fn retrieve_request_responses(
&self,
request: Option<&HttpRequest>,
) -> Result<Vec<Value>>
pub fn retrieve_request_responses( &self, request: Option<&HttpRequest>, ) -> Result<Vec<Value>>
Retrieve recorded request/response pairs.
Sourcepub fn has_started(&self, attempts: u32, timeout_ms: u64) -> bool
pub fn has_started(&self, attempts: u32, timeout_ms: u64) -> bool
Check if the MockServer has started (polls with retries).
Sourcepub fn add_breakpoint(
&self,
matcher: HttpRequest,
phases: &[&str],
request_handler: Option<BreakpointRequestHandler>,
response_handler: Option<BreakpointResponseHandler>,
stream_frame_handler: Option<BreakpointStreamFrameHandler>,
) -> Result<String>
pub fn add_breakpoint( &self, matcher: HttpRequest, phases: &[&str], request_handler: Option<BreakpointRequestHandler>, response_handler: Option<BreakpointResponseHandler>, stream_frame_handler: Option<BreakpointStreamFrameHandler>, ) -> Result<String>
Register a breakpoint matcher with the given phases and handlers. Returns the server-assigned breakpoint id.
Sourcepub fn add_request_breakpoint(
&self,
matcher: HttpRequest,
handler: BreakpointRequestHandler,
) -> Result<String>
pub fn add_request_breakpoint( &self, matcher: HttpRequest, handler: BreakpointRequestHandler, ) -> Result<String>
Convenience: register a REQUEST-only breakpoint.
Sourcepub fn add_request_response_breakpoint(
&self,
matcher: HttpRequest,
request_handler: BreakpointRequestHandler,
response_handler: BreakpointResponseHandler,
) -> Result<String>
pub fn add_request_response_breakpoint( &self, matcher: HttpRequest, request_handler: BreakpointRequestHandler, response_handler: BreakpointResponseHandler, ) -> Result<String>
Convenience: register a REQUEST + RESPONSE breakpoint.
Sourcepub fn add_stream_breakpoint(
&self,
matcher: HttpRequest,
phases: &[&str],
handler: BreakpointStreamFrameHandler,
) -> Result<String>
pub fn add_stream_breakpoint( &self, matcher: HttpRequest, phases: &[&str], handler: BreakpointStreamFrameHandler, ) -> Result<String>
Convenience: register a streaming-phase breakpoint.
Sourcepub fn list_breakpoint_matchers(&self) -> Result<BreakpointMatcherList>
pub fn list_breakpoint_matchers(&self) -> Result<BreakpointMatcherList>
List all registered breakpoint matchers.
Sourcepub fn remove_breakpoint_matcher(&self, id: impl Into<String>) -> Result<()>
pub fn remove_breakpoint_matcher(&self, id: impl Into<String>) -> Result<()>
Remove a breakpoint matcher by id.
Sourcepub fn clear_breakpoint_matchers(&self) -> Result<()>
pub fn clear_breakpoint_matchers(&self) -> Result<()>
Remove all registered breakpoint matchers.
Sourcepub fn close_breakpoint_websocket(&self)
pub fn close_breakpoint_websocket(&self)
Close the breakpoint callback WebSocket connection.