pub struct MockHttp { /* private fields */ }Expand description
A Http mock that replays contracts and records the calls it received.
Implementations§
Source§impl MockHttp
impl MockHttp
Sourcepub fn on_err(
self,
when: Match,
error: impl Fn() -> Error + Send + Sync + 'static,
) -> Self
pub fn on_err( self, when: Match, error: impl Fn() -> Error + Send + Sync + 'static, ) -> Self
Fail matching requests with an injected error (checked before reply contracts). Use this to
test that an adapter propagates a transport failure (e.g. a 429 → Error::Transient)
instead of swallowing it into an empty reading.
Sourcepub fn on_transient(self, when: Match) -> Self
pub fn on_transient(self, when: Match) -> Self
Fail matching requests with a retryable Error::Transient (an HTTP 429 stand-in).
Sourcepub fn from_contracts(contracts: Vec<Contract>) -> Self
pub fn from_contracts(contracts: Vec<Contract>) -> Self
Build from a pre-assembled contract set.
Trait Implementations§
Source§impl Http for MockHttp
impl Http for MockHttp
Source§fn post<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
body: String,
_headers: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn post<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
body: String,
_headers: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
POST a request body to
url with extra request headers, returning the raw response body.Source§fn get<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
_headers: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn get<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
_headers: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
GET
url with extra request headers, returning the raw response body.Auto Trait Implementations§
impl !Freeze for MockHttp
impl !RefUnwindSafe for MockHttp
impl !UnwindSafe for MockHttp
impl Send for MockHttp
impl Sync for MockHttp
impl Unpin for MockHttp
impl UnsafeUnpin for MockHttp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more