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
impl Expectation
Sourcepub fn new(request: HttpRequest) -> Self
pub fn new(request: HttpRequest) -> Self
Create a new expectation with the given request matcher.
Sourcepub fn respond(self, response: HttpResponse) -> Self
pub fn respond(self, response: HttpResponse) -> Self
Set a response action.
Sourcepub fn forward(self, forward: HttpForward) -> Self
pub fn forward(self, forward: HttpForward) -> Self
Set a forward action.
Sourcepub fn respond_template(self, template: HttpTemplate) -> Self
pub fn respond_template(self, template: HttpTemplate) -> Self
Set a response template action.
Sourcepub fn forward_template(self, template: HttpTemplate) -> Self
pub fn forward_template(self, template: HttpTemplate) -> Self
Set a forward template action.
Sourcepub fn respond_with_class_callback(
self,
callback_class: impl Into<String>,
) -> Self
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).
Sourcepub fn respond_class_callback(self, callback: HttpClassCallback) -> Self
pub fn respond_class_callback(self, callback: HttpClassCallback) -> Self
Respond via a pre-built HttpClassCallback (httpResponseClassCallback).
Sourcepub fn forward_with_class_callback(
self,
callback_class: impl Into<String>,
) -> Self
pub fn forward_with_class_callback( self, callback_class: impl Into<String>, ) -> Self
Forward via a server-side class callback (httpForwardClassCallback).
Sourcepub fn forward_class_callback(self, callback: HttpClassCallback) -> Self
pub fn forward_class_callback(self, callback: HttpClassCallback) -> Self
Forward via a pre-built HttpClassCallback (httpForwardClassCallback).
Sourcepub fn respond_object_callback(self, callback: HttpObjectCallback) -> Self
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.
Sourcepub fn forward_object_callback(self, callback: HttpObjectCallback) -> Self
pub fn forward_object_callback(self, callback: HttpObjectCallback) -> Self
Forward via an object/closure callback (httpForwardObjectCallback).
Sourcepub fn respond_sse(self, sse: HttpSseResponse) -> Self
pub fn respond_sse(self, sse: HttpSseResponse) -> Self
Set a Server-Sent Events (SSE) response action.
Sourcepub fn respond_web_socket(self, ws: HttpWebSocketResponse) -> Self
pub fn respond_web_socket(self, ws: HttpWebSocketResponse) -> Self
Set a WebSocket response action.
Sourcepub fn respond_dns(self, dns: DnsResponse) -> Self
pub fn respond_dns(self, dns: DnsResponse) -> Self
Set a DNS response action.
Sourcepub fn respond_binary(self, binary: BinaryResponse) -> Self
pub fn respond_binary(self, binary: BinaryResponse) -> Self
Set a raw binary response action.
Sourcepub fn respond_grpc_stream(self, grpc: GrpcStreamResponse) -> Self
pub fn respond_grpc_stream(self, grpc: GrpcStreamResponse) -> Self
Set a gRPC streaming response action.
Sourcepub fn time_to_live(self, ttl: TimeToLive) -> Self
pub fn time_to_live(self, ttl: TimeToLive) -> Self
Set the time-to-live.
Sourcepub fn scenario_name(self, name: impl Into<String>) -> Self
pub fn scenario_name(self, name: impl Into<String>) -> Self
Set the scenario (state-machine) name this expectation participates in.
Sourcepub fn scenario_state(self, state: impl Into<String>) -> Self
pub fn scenario_state(self, state: impl Into<String>) -> Self
Set the state the scenario must be in for this expectation to match.
Sourcepub fn new_scenario_state(self, state: impl Into<String>) -> Self
pub fn new_scenario_state(self, state: impl Into<String>) -> Self
Set the state the scenario transitions to after this expectation matches.
Sourcepub fn respond_with(self, response: HttpResponse) -> Self
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.
Sourcepub fn http_responses(self, responses: Vec<HttpResponse>) -> Self
pub fn http_responses(self, responses: Vec<HttpResponse>) -> Self
Replace all multiple responses (http_responses).
Sourcepub fn response_mode(self, mode: ResponseMode) -> Self
pub fn response_mode(self, mode: ResponseMode) -> Self
Set how a response is selected from http_responses.
Sourcepub fn response_weights(self, weights: Vec<i32>) -> Self
pub fn response_weights(self, weights: Vec<i32>) -> Self
Set the index-aligned relative weights for ResponseMode::Weighted.
Sourcepub fn switch_after(self, switch_after: i32) -> Self
pub fn switch_after(self, switch_after: i32) -> Self
Set the number of requests per response block before advancing under
ResponseMode::Switch.
Sourcepub fn cross_protocol_scenario(self, scenario: CrossProtocolScenario) -> Self
pub fn cross_protocol_scenario(self, scenario: CrossProtocolScenario) -> Self
Append a CrossProtocolScenario correlation.
Sourcepub fn cross_protocol_scenarios(
self,
scenarios: Vec<CrossProtocolScenario>,
) -> Self
pub fn cross_protocol_scenarios( self, scenarios: Vec<CrossProtocolScenario>, ) -> Self
Replace all cross-protocol scenario correlations.
Trait Implementations§
Source§impl Clone for Expectation
impl Clone for Expectation
Source§fn clone(&self) -> Expectation
fn clone(&self) -> Expectation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expectation
impl Debug for Expectation
Source§impl Default for Expectation
impl Default for Expectation
Source§fn default() -> Expectation
fn default() -> Expectation
Source§impl<'de> Deserialize<'de> for Expectation
impl<'de> Deserialize<'de> for Expectation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for Expectation
impl PartialEq for Expectation
Source§fn eq(&self, other: &Expectation) -> bool
fn eq(&self, other: &Expectation) -> bool
self and other values to be equal, and is used by ==.