pub struct TestResponse {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Bytes,
}Expand description
A fully buffered test response with chainable assertions.
Fields§
§status: StatusCodeHTTP response status.
headers: HeaderMapHTTP response headers.
body: BytesRaw response bytes.
Implementations§
Source§impl TestResponse
impl TestResponse
Extract only a named cookie’s name/value pair; omit Set-Cookie attributes. The returned sensitive header value redacts its Debug output.
Sourcepub fn assert_status(&self, status: impl Into<StatusCode>) -> &Self
pub fn assert_status(&self, status: impl Into<StatusCode>) -> &Self
Assert any HTTP status, including custom application error statuses.
Sourcepub fn assert_created(&self) -> &Self
pub fn assert_created(&self) -> &Self
Assert HTTP 201.
Sourcepub fn assert_no_content(&self) -> &Self
pub fn assert_no_content(&self) -> &Self
Assert HTTP 204 and an empty response body.
Sourcepub fn json<T: DeserializeOwned>(&self) -> T
pub fn json<T: DeserializeOwned>(&self) -> T
Deserialize the response into a JSON value or application response type.
Sourcepub fn assert_json(&self, expected: Value) -> &Self
pub fn assert_json(&self, expected: Value) -> &Self
Assert exact JSON equality, independent of object key order.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TestResponse
impl RefUnwindSafe for TestResponse
impl Send for TestResponse
impl Sync for TestResponse
impl Unpin for TestResponse
impl UnsafeUnpin for TestResponse
impl UnwindSafe for TestResponse
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