pub struct MockHttp { /* private fields */ }Expand description
Mock HTTP provider for testing.
Allows defining rules that match requests and return mock responses.
§Example
use xerv_core::testing::{MockHttp, MockHttpRule, HttpResponse};
use serde_json::json;
let mock = MockHttp::new()
.rule(
MockHttpRule::new(r"^https://api\.example\.com/users/\d+$", HttpResponse::json(200, &json!({"name": "Alice"})))
.with_method("GET")
)
.rule(
MockHttpRule::new(r"^https://api\.example\.com/users$", HttpResponse::json(201, &json!({"id": 1})))
.with_method("POST")
);Implementations§
Source§impl MockHttp
impl MockHttp
Sourcepub fn rule(self, rule: MockHttpRule) -> Self
pub fn rule(self, rule: MockHttpRule) -> Self
Add a rule.
Sourcepub fn fail_on_unmatched(self, fail: bool) -> Self
pub fn fail_on_unmatched(self, fail: bool) -> Self
Set whether to fail on unmatched requests.
Sourcepub fn on_get(self, url_pattern: &str) -> MockHttpBuilder
pub fn on_get(self, url_pattern: &str) -> MockHttpBuilder
Fluent builder: start defining a GET rule.
Sourcepub fn on_post(self, url_pattern: &str) -> MockHttpBuilder
pub fn on_post(self, url_pattern: &str) -> MockHttpBuilder
Fluent builder: start defining a POST rule.
Sourcepub fn on_put(self, url_pattern: &str) -> MockHttpBuilder
pub fn on_put(self, url_pattern: &str) -> MockHttpBuilder
Fluent builder: start defining a PUT rule.
Sourcepub fn on_delete(self, url_pattern: &str) -> MockHttpBuilder
pub fn on_delete(self, url_pattern: &str) -> MockHttpBuilder
Fluent builder: start defining a DELETE rule.
Sourcepub fn on_any(self, url_pattern: &str) -> MockHttpBuilder
pub fn on_any(self, url_pattern: &str) -> MockHttpBuilder
Fluent builder: start defining a rule matching any method.
Sourcepub fn clear_requests(&self)
pub fn clear_requests(&self)
Clear recorded requests.
Sourcepub fn assert_request_made(&self, method: &str, url_pattern: &str) -> bool
pub fn assert_request_made(&self, method: &str, url_pattern: &str) -> bool
Assert that a specific request was made.
Sourcepub fn request_count(&self) -> usize
pub fn request_count(&self) -> usize
Get the number of requests made.
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 UnwindSafe for MockHttp
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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> 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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.