Struct axum_test::TestResponse
source · pub struct TestResponse { /* private fields */ }Expand description
This contains the response from the server.
Inside are the contents of the response, the status code, and some debugging information.
You can get the contents out as it’s raw string, or deserialise it.
One can also also use the assert_* functions to test against the
response.
Implementations§
source§impl TestResponse
impl TestResponse
sourcepub fn request_url<'a>(&'a self) -> &'a str
pub fn request_url<'a>(&'a self) -> &'a str
The URL that was used to produce this response.
sourcepub fn bytes<'a>(&'a self) -> &'a [u8] ⓘ
pub fn bytes<'a>(&'a self) -> &'a [u8] ⓘ
Returns the raw underlying response, as it’s raw bytes.
sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
The status_code of the response.
pub fn header<N>(&self, header_name: N) -> Option<HeaderValue>where N: AsHeaderName,
pub fn iter_headers<'a>( &'a self ) -> impl Iterator<Item = (&'a HeaderName, &'a HeaderValue)>
pub fn iter_headers_by_name<'a, N>( &'a self, header_name: N ) -> impl Iterator<Item = &'a HeaderValue>where N: AsHeaderName,
sourcepub fn json<T>(&self) -> Twhere
for<'de> T: Deserialize<'de>,
pub fn json<T>(&self) -> Twhere for<'de> T: Deserialize<'de>,
Reads the response from the server as JSON text, and then deserialise the contents into the structure given.
sourcepub fn assert_text<C>(self, other: C) -> Selfwhere
C: AsRef<str>,
pub fn assert_text<C>(self, other: C) -> Selfwhere C: AsRef<str>,
This performs an assertion comparing the whole body of the response, against the text provided.
sourcepub fn assert_json<T>(self, other: &T) -> Selfwhere
for<'de> T: Deserialize<'de> + PartialEq<T> + Debug,
pub fn assert_json<T>(self, other: &T) -> Selfwhere for<'de> T: Deserialize<'de> + PartialEq<T> + Debug,
Deserializes the contents of the request, and asserts if it matches the value given.
If other does not match, then this will panic.
Other can be your own Serde model that you wish to deserialise
the data into, or it can be a json! blob created using
the ::serde_json::json macro.
pub fn assert_status_bad_request(self) -> Self
pub fn assert_status_not_found(self) -> Self
pub fn assert_status_ok(self) -> Self
pub fn assert_status_not_ok(self) -> Self
pub fn assert_status(self, status_code: StatusCode) -> Self
pub fn assert_not_status(self, status_code: StatusCode) -> Self
Trait Implementations§
source§impl Clone for TestResponse
impl Clone for TestResponse
source§fn clone(&self) -> TestResponse
fn clone(&self) -> TestResponse
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more