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.
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.