Skip to main content

MockServerClient

Struct MockServerClient 

Source
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

Source

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.

Source

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();
Source

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.

Source

pub fn verify_sequence(&self, requests: Vec<HttpRequest>) -> Result<()>

Verify that requests were received in the given order.

Source

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.

Source

pub fn clear_by_id( &self, expectation_id: impl Into<String>, clear_type: Option<ClearType>, ) -> Result<()>

Clear expectations by expectation ID.

Source

pub fn reset(&self) -> Result<()>

Reset all expectations and recorded requests.

Source

pub fn retrieve_recorded_requests( &self, request: Option<&HttpRequest>, ) -> Result<Vec<HttpRequest>>

Retrieve recorded requests matching the optional filter.

Source

pub fn retrieve_active_expectations( &self, request: Option<&HttpRequest>, ) -> Result<Vec<Expectation>>

Retrieve active expectations matching the optional filter.

Source

pub fn retrieve_recorded_expectations( &self, request: Option<&HttpRequest>, ) -> Result<Vec<Expectation>>

Retrieve recorded expectations matching the optional filter.

Source

pub fn retrieve_log_messages( &self, request: Option<&HttpRequest>, ) -> Result<Vec<String>>

Retrieve log messages matching the optional filter.

Source

pub fn retrieve_request_responses( &self, request: Option<&HttpRequest>, ) -> Result<Vec<Value>>

Retrieve recorded request/response pairs.

Source

pub fn status(&self) -> Result<Ports>

Query the server’s listening ports.

Source

pub fn bind(&self, ports: &[u16]) -> Result<Ports>

Bind additional listening ports.

Source

pub fn has_started(&self, attempts: u32, timeout_ms: u64) -> bool

Check if the MockServer has started (polls with retries).

Source

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.

Source

pub fn add_request_breakpoint( &self, matcher: HttpRequest, handler: BreakpointRequestHandler, ) -> Result<String>

Convenience: register a REQUEST-only breakpoint.

Source

pub fn add_request_response_breakpoint( &self, matcher: HttpRequest, request_handler: BreakpointRequestHandler, response_handler: BreakpointResponseHandler, ) -> Result<String>

Convenience: register a REQUEST + RESPONSE breakpoint.

Source

pub fn add_stream_breakpoint( &self, matcher: HttpRequest, phases: &[&str], handler: BreakpointStreamFrameHandler, ) -> Result<String>

Convenience: register a streaming-phase breakpoint.

Source

pub fn list_breakpoint_matchers(&self) -> Result<BreakpointMatcherList>

List all registered breakpoint matchers.

Source

pub fn remove_breakpoint_matcher(&self, id: impl Into<String>) -> Result<()>

Remove a breakpoint matcher by id.

Source

pub fn clear_breakpoint_matchers(&self) -> Result<()>

Remove all registered breakpoint matchers.

Source

pub fn close_breakpoint_websocket(&self)

Close the breakpoint callback WebSocket connection.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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