pub struct Mock { /* private fields */ }Available on
test and crate feature mock_tests only.Expand description
Mock Responses and validate Requests. All responses of a thread will be checked against the Mock if at least one Endpoint is Mocked. Otherwise a normal web request is done
use generic_async_http_client::{Request, Error, Mock};
Mock::update("GET", "http://example.com/", |r|{
r.set_response(200, "mock");
r.add_response_header("test", "jo").unwrap();
});
let mut resp = Request::get("http://example.com/").exec().await?;
assert_eq!(resp.header("test").unwrap(), "jo");
assert_eq!(resp.text().await?, "mock");Implementations§
Source§impl Mock
impl Mock
Sourcepub fn add(meth: &str, uri: &str, mep: MockedEndpoint)
Available on docsrs only.
pub fn add(meth: &str, uri: &str, mep: MockedEndpoint)
docsrs only.Add a Mocked endpoint
meth and uri must be an exact match
Sourcepub fn update<F>(meth: &str, uri: &str, f: F)where
F: FnOnce(&mut MockedEndpoint),
Available on docsrs only.
pub fn update<F>(meth: &str, uri: &str, f: F)where
F: FnOnce(&mut MockedEndpoint),
docsrs only.Add or update a Mocked endpoint
meth and uri must be an exact match
pub fn uses_mock() -> bool
Available on
docsrs only.Auto Trait Implementations§
impl Freeze for Mock
impl RefUnwindSafe for Mock
impl Send for Mock
impl Sync for Mock
impl Unpin for Mock
impl UnsafeUnpin for Mock
impl UnwindSafe for Mock
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