pub struct Expectation {Show 42 fields
pub id: Option<String>,
pub priority: Option<i32>,
pub percentage: Option<i32>,
pub chaos: Option<HttpChaosProfile>,
pub rate_limit: Option<RateLimit>,
pub http_request: Option<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_override_forwarded_request: Option<HttpOverrideForwardedRequest>,
pub http_forward_validate_action: Option<HttpForwardValidateAction>,
pub http_forward_with_fallback: Option<HttpForwardWithFallback>,
pub http_sse_response: Option<HttpSseResponse>,
pub http_llm_response: Option<HttpLlmResponse>,
pub http_web_socket_response: Option<HttpWebSocketResponse>,
pub dns_response: Option<DnsResponse>,
pub binary_response: Option<BinaryResponse>,
pub grpc_stream_response: Option<GrpcStreamResponse>,
pub grpc_bidi_response: Option<GrpcBidiResponse>,
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>>,
pub before_actions: Option<Vec<ExpectationAction>>,
pub after_actions: Option<Vec<ExpectationAction>>,
pub capture: Option<Vec<CaptureRule>>,
pub namespace: Option<String>,
pub steps: Option<Vec<ExpectationStep>>,
pub timestamp: Option<String>,
pub extra: Extra,
}Expand description
A full expectation combining a request matcher with an action.
Fields§
§id: Option<String>§priority: Option<i32>§percentage: Option<i32>Match only a percentage (0–100) of otherwise-matching requests.
chaos: Option<HttpChaosProfile>Declarative HTTP chaos / fault-injection profile.
rate_limit: Option<RateLimit>Declarative, protocol-agnostic rate limit / quota.
http_request: Option<HttpRequest>Request matcher. Optional because a steps-only (or side-effect-only)
expectation carries no top-level request. Omitted from the wire form when
None; an explicitly empty HttpRequest still serialises as {}.
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_override_forwarded_request: Option<HttpOverrideForwardedRequest>Override the forwarded request/response (httpOverrideForwardedRequest).
http_forward_validate_action: Option<HttpForwardValidateAction>Forward and validate against an OpenAPI spec (httpForwardValidateAction).
http_forward_with_fallback: Option<HttpForwardWithFallback>Forward with a fallback response on failure (httpForwardWithFallback).
http_sse_response: Option<HttpSseResponse>§http_llm_response: Option<HttpLlmResponse>LLM response action (httpLlmResponse).
http_web_socket_response: Option<HttpWebSocketResponse>§dns_response: Option<DnsResponse>§binary_response: Option<BinaryResponse>§grpc_stream_response: Option<GrpcStreamResponse>§grpc_bidi_response: Option<GrpcBidiResponse>gRPC bidirectional-streaming response action (grpcBidiResponse).
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.
before_actions: Option<Vec<ExpectationAction>>Side-effect actions run before the main action fires (beforeActions).
The server accepts a single object or an array; this client accepts both on the wire and always serialises an array.
after_actions: Option<Vec<ExpectationAction>>Side-effect actions run after the main action fires (afterActions).
capture: Option<Vec<CaptureRule>>Capture rules that bind request values into scenario/template state.
namespace: Option<String>Optional namespace (tenant) this expectation belongs to.
steps: Option<Vec<ExpectationStep>>Multi-step script for a single match (steps).
timestamp: Option<String>Creation timestamp (set by the server; round-tripped when present).
extra: ExtraForward-compatibility catch-all for any expectation field the typed model does not yet name, so unknown fields survive a round-trip instead of being silently dropped.
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.
Sourcepub fn percentage(self, percentage: i32) -> Self
pub fn percentage(self, percentage: i32) -> Self
Match only a percentage (0–100) of otherwise-matching requests.
Sourcepub fn chaos(self, chaos: HttpChaosProfile) -> Self
pub fn chaos(self, chaos: HttpChaosProfile) -> Self
Attach a declarative HTTP chaos / fault-injection profile.
Sourcepub fn rate_limit(self, rate_limit: RateLimit) -> Self
pub fn rate_limit(self, rate_limit: RateLimit) -> Self
Attach a declarative rate limit / quota.
Sourcepub fn override_forwarded_request(
self,
override_request: HttpOverrideForwardedRequest,
) -> Self
pub fn override_forwarded_request( self, override_request: HttpOverrideForwardedRequest, ) -> Self
Override the forwarded request/response (httpOverrideForwardedRequest).
Sourcepub fn forward_validate(self, action: HttpForwardValidateAction) -> Self
pub fn forward_validate(self, action: HttpForwardValidateAction) -> Self
Forward and validate against an OpenAPI spec (httpForwardValidateAction).
Sourcepub fn forward_with_fallback(self, action: HttpForwardWithFallback) -> Self
pub fn forward_with_fallback(self, action: HttpForwardWithFallback) -> Self
Forward with a fallback response on failure (httpForwardWithFallback).
Sourcepub fn respond_llm(self, llm: HttpLlmResponse) -> Self
pub fn respond_llm(self, llm: HttpLlmResponse) -> Self
Set an LLM response action (httpLlmResponse).
Sourcepub fn respond_grpc_bidi(self, grpc: GrpcBidiResponse) -> Self
pub fn respond_grpc_bidi(self, grpc: GrpcBidiResponse) -> Self
Set a gRPC bidirectional-streaming response action (grpcBidiResponse).
Sourcepub fn before_action(self, action: ExpectationAction) -> Self
pub fn before_action(self, action: ExpectationAction) -> Self
Append a before-action (beforeActions).
Sourcepub fn after_action(self, action: ExpectationAction) -> Self
pub fn after_action(self, action: ExpectationAction) -> Self
Append an after-action (afterActions).
Sourcepub fn capture_rule(self, rule: CaptureRule) -> Self
pub fn capture_rule(self, rule: CaptureRule) -> Self
Append a capture rule (capture).
Sourcepub fn namespace(self, namespace: impl Into<String>) -> Self
pub fn namespace(self, namespace: impl Into<String>) -> Self
Set the namespace (tenant) this expectation belongs to.
Sourcepub fn step(self, step: ExpectationStep) -> Self
pub fn step(self, step: ExpectationStep) -> Self
Append a step to the multi-step script (steps).
Sourcepub fn steps(self, steps: Vec<ExpectationStep>) -> Self
pub fn steps(self, steps: Vec<ExpectationStep>) -> Self
Replace all steps (steps).
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 ==.