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_request_and_response(
&self,
request: HttpRequest,
response: HttpResponse,
times: VerificationTimes,
) -> Result<()>
pub fn verify_request_and_response( &self, request: HttpRequest, response: HttpResponse, times: VerificationTimes, ) -> Result<()>
Verify that a request/response pair was received the specified number of times.
Both the request matcher and the response matcher must match for a
recorded exchange to count. The response matcher uses the same
HttpResponse type as expectations — the server matches against the
recorded response’s status code, headers, and body.
Sourcepub fn verify_response(
&self,
response: HttpResponse,
times: VerificationTimes,
) -> Result<()>
pub fn verify_response( &self, response: HttpResponse, times: VerificationTimes, ) -> Result<()>
Verify that a response (regardless of request) was returned the specified number of times.
The httpRequest field is omitted from the JSON so the server matches
any request.
Sourcepub fn verify_raw(&self, verification: &Verification) -> Result<()>
pub fn verify_raw(&self, verification: &Verification) -> Result<()>
Send a fully constructed Verification to the server.
This is the most flexible form — callers can set every field,
including maximum_number_of_request_to_return_in_verification_failure.
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 verify_sequence_with_responses(
&self,
requests: Vec<HttpRequest>,
responses: Vec<HttpResponse>,
) -> Result<()>
pub fn verify_sequence_with_responses( &self, requests: Vec<HttpRequest>, responses: Vec<HttpResponse>, ) -> Result<()>
Verify that request/response pairs were received in the given order.
responses is index-aligned with requests — each entry constrains
the response that must have been returned for the corresponding request.
Sourcepub fn verify_sequence_raw(
&self,
verification: &VerificationSequence,
) -> Result<()>
pub fn verify_sequence_raw( &self, verification: &VerificationSequence, ) -> Result<()>
Send a fully constructed VerificationSequence to the server.
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.