Skip to main content

Expectation

Struct Expectation 

Source
pub struct Expectation {
Show 27 fields pub id: Option<String>, pub priority: Option<i32>, pub http_request: HttpRequest, pub http_response: Option<HttpResponse>, pub http_forward: Option<HttpForward>, pub http_response_template: Option<HttpTemplate>, pub http_forward_template: Option<HttpTemplate>, pub http_error: Option<HttpError>, pub http_response_class_callback: Option<HttpClassCallback>, pub http_forward_class_callback: Option<HttpClassCallback>, pub http_response_object_callback: Option<HttpObjectCallback>, pub http_forward_object_callback: Option<HttpObjectCallback>, pub http_sse_response: Option<HttpSseResponse>, pub http_web_socket_response: Option<HttpWebSocketResponse>, pub dns_response: Option<DnsResponse>, pub binary_response: Option<BinaryResponse>, pub grpc_stream_response: Option<GrpcStreamResponse>, pub times: Option<Times>, pub time_to_live: Option<TimeToLive>, pub scenario_name: Option<String>, pub scenario_state: Option<String>, pub new_scenario_state: Option<String>, pub http_responses: Option<Vec<HttpResponse>>, pub response_mode: Option<ResponseMode>, pub response_weights: Option<Vec<i32>>, pub switch_after: Option<i32>, pub cross_protocol_scenarios: Option<Vec<CrossProtocolScenario>>,
}
Expand description

A full expectation combining a request matcher with an action.

Fields§

§id: Option<String>§priority: Option<i32>§http_request: HttpRequest§http_response: Option<HttpResponse>§http_forward: Option<HttpForward>§http_response_template: Option<HttpTemplate>§http_forward_template: Option<HttpTemplate>§http_error: Option<HttpError>§http_response_class_callback: Option<HttpClassCallback>

Class callback that produces the response (serialized as httpResponseClassCallback).

§http_forward_class_callback: Option<HttpClassCallback>

Class callback that produces the request to forward (serialized as httpForwardClassCallback).

§http_response_object_callback: Option<HttpObjectCallback>

Object/closure callback that produces the response (serialized as httpResponseObjectCallback).

§http_forward_object_callback: Option<HttpObjectCallback>

Object/closure callback that produces the request to forward (serialized as httpForwardObjectCallback).

§http_sse_response: Option<HttpSseResponse>§http_web_socket_response: Option<HttpWebSocketResponse>§dns_response: Option<DnsResponse>§binary_response: Option<BinaryResponse>§grpc_stream_response: Option<GrpcStreamResponse>§times: Option<Times>§time_to_live: Option<TimeToLive>§scenario_name: Option<String>

Name of the state-machine this expectation participates in.

§scenario_state: Option<String>

State the scenario must be in for this expectation to match.

§new_scenario_state: Option<String>

State the scenario transitions to after this expectation matches.

§http_responses: Option<Vec<HttpResponse>>

Multiple responses; takes priority over the singular Expectation::http_response.

§response_mode: Option<ResponseMode>

How a response is selected from Expectation::http_responses.

§response_weights: Option<Vec<i32>>

Index-aligned relative weights for ResponseMode::Weighted.

§switch_after: Option<i32>

Requests per response block before advancing under ResponseMode::Switch (default 1).

§cross_protocol_scenarios: Option<Vec<CrossProtocolScenario>>

Cross-protocol scenario correlations that advance scenario state on protocol events.

Implementations§

Source§

impl Expectation

Source

pub fn new(request: HttpRequest) -> Self

Create a new expectation with the given request matcher.

Source

pub fn id(self, id: impl Into<String>) -> Self

Set the expectation ID (for upsert semantics).

Source

pub fn priority(self, priority: i32) -> Self

Set the priority (higher = matched first).

Source

pub fn respond(self, response: HttpResponse) -> Self

Set a response action.

Source

pub fn forward(self, forward: HttpForward) -> Self

Set a forward action.

Source

pub fn respond_template(self, template: HttpTemplate) -> Self

Set a response template action.

Source

pub fn forward_template(self, template: HttpTemplate) -> Self

Set a forward template action.

Source

pub fn error(self, error: HttpError) -> Self

Set an error action.

Source

pub fn respond_with_class_callback( self, callback_class: impl Into<String>, ) -> Self

Respond via a server-side class callback (httpResponseClassCallback).

The named class must implement MockServer’s callback interface and be on the server’s classpath. Convenience over building an HttpClassCallback directly; use respond_class_callback for the full builder (delay, primary).

Source

pub fn respond_class_callback(self, callback: HttpClassCallback) -> Self

Respond via a pre-built HttpClassCallback (httpResponseClassCallback).

Source

pub fn forward_with_class_callback( self, callback_class: impl Into<String>, ) -> Self

Forward via a server-side class callback (httpForwardClassCallback).

Source

pub fn forward_class_callback(self, callback: HttpClassCallback) -> Self

Forward via a pre-built HttpClassCallback (httpForwardClassCallback).

Source

pub fn respond_object_callback(self, callback: HttpObjectCallback) -> Self

Respond via an object/closure callback (httpResponseObjectCallback).

Most users should call MockServerClient::mock_with_callback instead, which opens the callback WebSocket, registers the closure, and fills in the client_id automatically.

Source

pub fn forward_object_callback(self, callback: HttpObjectCallback) -> Self

Forward via an object/closure callback (httpForwardObjectCallback).

Source

pub fn respond_sse(self, sse: HttpSseResponse) -> Self

Set a Server-Sent Events (SSE) response action.

Source

pub fn respond_web_socket(self, ws: HttpWebSocketResponse) -> Self

Set a WebSocket response action.

Source

pub fn respond_dns(self, dns: DnsResponse) -> Self

Set a DNS response action.

Source

pub fn respond_binary(self, binary: BinaryResponse) -> Self

Set a raw binary response action.

Source

pub fn respond_grpc_stream(self, grpc: GrpcStreamResponse) -> Self

Set a gRPC streaming response action.

Source

pub fn times(self, times: Times) -> Self

Set the number of times this expectation matches.

Source

pub fn time_to_live(self, ttl: TimeToLive) -> Self

Set the time-to-live.

Source

pub fn scenario_name(self, name: impl Into<String>) -> Self

Set the scenario (state-machine) name this expectation participates in.

Source

pub fn scenario_state(self, state: impl Into<String>) -> Self

Set the state the scenario must be in for this expectation to match.

Source

pub fn new_scenario_state(self, state: impl Into<String>) -> Self

Set the state the scenario transitions to after this expectation matches.

Source

pub fn respond_with(self, response: HttpResponse) -> Self

Append a response to the multiple-responses list (http_responses).

When set, http_responses takes priority over the singular respond action.

Source

pub fn http_responses(self, responses: Vec<HttpResponse>) -> Self

Replace all multiple responses (http_responses).

Source

pub fn response_mode(self, mode: ResponseMode) -> Self

Set how a response is selected from http_responses.

Source

pub fn response_weights(self, weights: Vec<i32>) -> Self

Set the index-aligned relative weights for ResponseMode::Weighted.

Source

pub fn switch_after(self, switch_after: i32) -> Self

Set the number of requests per response block before advancing under ResponseMode::Switch.

Source

pub fn cross_protocol_scenario(self, scenario: CrossProtocolScenario) -> Self

Append a CrossProtocolScenario correlation.

Source

pub fn cross_protocol_scenarios( self, scenarios: Vec<CrossProtocolScenario>, ) -> Self

Replace all cross-protocol scenario correlations.

Trait Implementations§

Source§

impl Clone for Expectation

Source§

fn clone(&self) -> Expectation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expectation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Expectation

Source§

fn default() -> Expectation

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Expectation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Expectation

Source§

fn eq(&self, other: &Expectation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Expectation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Expectation

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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