pub struct RestHarness { /* private fields */ }Expand description
Mounts a router and exercises the real pipeline: routing, extractors, middlewares and guards, validation, and error mapping.
ⓘ
let harness = RestHarness::new(UserController::register_routes(&container, Router::new()));
let response = harness.get("/users/1").send().await;
assert_eq!(response.status, 200);
assert_eq!(response.json::<User>().name, "Ada");Implementations§
Source§impl RestHarness
impl RestHarness
pub fn new(router: Router) -> Self
Sourcepub fn with_header(
&self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( &self, name: impl Into<String>, value: impl Into<String>, ) -> Self
A client that sends name: value on every request — a bearer
token, an API key, a tenant header.
Returns a new harness rather than mutating: a test usually wants both the authenticated and the anonymous client, and comparing them is the point.
Sourcepub fn with_bearer(&self, token: impl Display) -> Self
pub fn with_bearer(&self, token: impl Display) -> Self
A client authenticating with Authorization: Bearer ….
A client sending the token in a cookie, for a guard configured to read one.
pub fn get(&self, path: &str) -> RequestBuilder
pub fn post(&self, path: &str) -> RequestBuilder
pub fn put(&self, path: &str) -> RequestBuilder
pub fn delete(&self, path: &str) -> RequestBuilder
pub fn request(&self, method: &str, path: &str) -> RequestBuilder
Trait Implementations§
Source§impl Clone for RestHarness
impl Clone for RestHarness
Source§fn clone(&self) -> RestHarness
fn clone(&self) -> RestHarness
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for RestHarness
impl !UnwindSafe for RestHarness
impl Freeze for RestHarness
impl Send for RestHarness
impl Sync for RestHarness
impl Unpin for RestHarness
impl UnsafeUnpin for RestHarness
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