pub struct ResponseStub {
pub method: String,
pub path: String,
pub status: u16,
pub headers: HashMap<String, String>,
pub body: Value,
pub latency_ms: Option<u64>,
pub state_machine: Option<StateMachineConfig>,
pub fault_injection: Option<StubFaultInjectionConfig>,
}Expand description
A response stub for mocking API endpoints
Fields§
§method: StringHTTP method (GET, POST, PUT, DELETE, etc.)
path: StringPath pattern (supports {{path_params}})
status: u16HTTP status code
headers: HashMap<String, String>Response headers
body: ValueResponse body (supports templates like {{uuid}}, {{faker.name}})
latency_ms: Option<u64>Optional latency in milliseconds
state_machine: Option<StateMachineConfig>Optional state machine configuration for stateful behavior When set, responses will vary based on resource state
fault_injection: Option<StubFaultInjectionConfig>Optional fault injection configuration for error simulation When set, can inject errors, timeouts, or connection failures
Implementations§
Source§impl ResponseStub
impl ResponseStub
Sourcepub fn new(
method: impl Into<String>,
path: impl Into<String>,
body: Value,
) -> Self
pub fn new( method: impl Into<String>, path: impl Into<String>, body: Value, ) -> Self
Create a new response stub
Sourcepub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a response header
Sourcepub fn with_state_machine(self, config: StateMachineConfig) -> Self
pub fn with_state_machine(self, config: StateMachineConfig) -> Self
Set state machine configuration for stateful behavior
Sourcepub fn has_state_machine(&self) -> bool
pub fn has_state_machine(&self) -> bool
Check if this stub has state machine configuration
Sourcepub fn state_machine(&self) -> Option<&StateMachineConfig>
pub fn state_machine(&self) -> Option<&StateMachineConfig>
Get state machine configuration
Sourcepub fn apply_state_override(&self, current_state: &str) -> ResponseStub
pub fn apply_state_override(&self, current_state: &str) -> ResponseStub
Apply state-based response override if state machine is configured
This method checks if the stub has state machine configuration and applies state-based response overrides based on the current state.
Returns a modified stub with state-specific overrides applied, or the original stub if no state machine config or no override for current state.
Sourcepub fn with_fault_injection(self, config: StubFaultInjectionConfig) -> Self
pub fn with_fault_injection(self, config: StubFaultInjectionConfig) -> Self
Set fault injection configuration
Sourcepub fn has_fault_injection(&self) -> bool
pub fn has_fault_injection(&self) -> bool
Check if this stub has fault injection configured
Sourcepub fn fault_injection(&self) -> Option<&StubFaultInjectionConfig>
pub fn fault_injection(&self) -> Option<&StubFaultInjectionConfig>
Get fault injection configuration
Trait Implementations§
Source§impl Clone for ResponseStub
impl Clone for ResponseStub
Source§fn clone(&self) -> ResponseStub
fn clone(&self) -> ResponseStub
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more