pub struct MockHttpClient { /* private fields */ }Expand description
Mock HTTP client for testing.
Queues responses to be returned by subsequent requests. Tracks all requests made for assertions.
§Example
ⓘ
let mut mock = MockHttpClient::new();
mock.queue_response(HttpResponse::ok(r#"{"key": "value"}"#.as_bytes().to_vec()));
let response = mock.get("https://example.com").await?;
assert_eq!(response.status, 200);
// Verify the request was made
assert_eq!(mock.requests()[0].url, "https://example.com");Implementations§
Source§impl MockHttpClient
impl MockHttpClient
Sourcepub fn queue_response(&self, response: HttpResponse)
pub fn queue_response(&self, response: HttpResponse)
Queue a response to be returned by the next request.
Sourcepub fn queue_error(&self, error: SteamError)
pub fn queue_error(&self, error: SteamError)
Queue an error to be returned by the next request.
Sourcepub fn queue_responses(&self, responses: Vec<HttpResponse>)
pub fn queue_responses(&self, responses: Vec<HttpResponse>)
Queue multiple responses.
Sourcepub fn requests(&self) -> Vec<MockRequest>
pub fn requests(&self) -> Vec<MockRequest>
Get all recorded requests.
Sourcepub fn last_request(&self) -> Option<MockRequest>
pub fn last_request(&self) -> Option<MockRequest>
Get the last request made.
Sourcepub fn clear_requests(&self)
pub fn clear_requests(&self)
Clear all recorded requests.
Sourcepub fn request_count(&self) -> usize
pub fn request_count(&self) -> usize
Get the number of requests made.
Trait Implementations§
Source§impl Clone for MockHttpClient
impl Clone for MockHttpClient
Source§impl Default for MockHttpClient
impl Default for MockHttpClient
Source§impl HttpClient for MockHttpClient
impl HttpClient for MockHttpClient
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Perform a GET request. Read more
Source§fn get_with_query<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
query: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn get_with_query<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
query: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Perform a GET request with query parameters. Read more
Source§fn post<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
url: &'life1 str,
body: Vec<u8>,
content_type: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn post<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
url: &'life1 str,
body: Vec<u8>,
content_type: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Perform a POST request with a body. Read more
Source§fn post_form<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
form: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn post_form<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
url: &'life1 str,
form: &'life2 [(&'life3 str, &'life4 str)],
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, SteamError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Perform a POST request with form data. Read more
Perform a GET request carrying a raw
Cookie header value. Read morePerform a POST form request carrying a raw
Cookie header value. Read moreAuto Trait Implementations§
impl Freeze for MockHttpClient
impl RefUnwindSafe for MockHttpClient
impl Send for MockHttpClient
impl Sync for MockHttpClient
impl Unpin for MockHttpClient
impl UnsafeUnpin for MockHttpClient
impl UnwindSafe for MockHttpClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more