pub struct MockHttp { /* private fields */ }Expand description
Mock HTTP client for testing.
Mocks are matched first-registered-wins: the first handler whose pattern matches the request URL (or path) is used. Register specific patterns before broad wildcards.
Patterns are matched against both the full URL and the path component,
so "/health" matches a request to https://internal:8080/health.
Implementations§
Source§impl MockHttp
impl MockHttp
pub fn new() -> Self
pub fn builder() -> MockHttpBuilder
Sourcepub fn add_mock_sync<F>(&self, pattern: &str, handler: F)
pub fn add_mock_sync<F>(&self, pattern: &str, handler: F)
Add a mock handler (sync version for use in builders).
The pattern supports * as a glob wildcard. Mocks are matched
first-registered-wins against both the full URL and the path.
Sourcepub fn mock_exact<F>(&self, url: &str, handler: F)
pub fn mock_exact<F>(&self, url: &str, handler: F)
No wildcards; use mock_glob for patterns.
Sourcepub fn mock_glob<F>(&self, pattern: &str, handler: F)
pub fn mock_glob<F>(&self, pattern: &str, handler: F)
Add a mock handler with glob pattern (* matches any substring).
Register specific patterns before broad ones — first match wins.
pub fn add_mock_boxed(&mut self, pattern: &str, handler: BoxedHandler)
pub async fn execute(&self, request: MockRequest) -> MockResponse
pub fn requests(&self) -> Vec<RecordedRequest>
pub fn requests_blocking(&self) -> Vec<RecordedRequest>
pub fn requests_to(&self, pattern: &str) -> Vec<RecordedRequest>
pub fn clear_requests(&self)
pub fn clear_mocks(&self)
Sourcepub fn assert_called(&self, pattern: &str)
pub fn assert_called(&self, pattern: &str)
Assert that a URL pattern was called.
Sourcepub fn assert_called_times(&self, pattern: &str, expected: usize)
pub fn assert_called_times(&self, pattern: &str, expected: usize)
Assert that a URL pattern was called a specific number of times.
Sourcepub fn assert_not_called(&self, pattern: &str)
pub fn assert_not_called(&self, pattern: &str)
Assert that a URL pattern was not called.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MockHttp
impl RefUnwindSafe for MockHttp
impl Send for MockHttp
impl Sync for MockHttp
impl Unpin for MockHttp
impl UnsafeUnpin for MockHttp
impl UnwindSafe 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
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>
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>
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