Struct axum_test::TestResponse
source · pub struct TestResponse { /* private fields */ }Expand description
The TestResponse represents the result of a TestRequest.
It is returned when you call await on a TestRequest object.
Inside are the contents of the response, the status code, and some debugging information. You can use this to deserialise the data returned into a specific format (i.e. deserialising from JSON), and validating the response looks how you expect.
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 maybe_header<N>(&self, header_name: N) -> Option<HeaderValue>where
N: AsHeaderName,
pub fn maybe_header<N>(&self, header_name: N) -> Option<HeaderValue>where N: AsHeaderName,
Finds a header with the given name. If there are multiple headers with the same name, then only the first will be returned.
None is returned when no header was found.
sourcepub fn header<N>(&self, header_name: N) -> HeaderValuewhere
N: AsHeaderName + Display + Clone,
pub fn header<N>(&self, header_name: N) -> HeaderValuewhere N: AsHeaderName + Display + Clone,
Finds a header with the given name. If there are multiple headers with the same name, then only the first will be returned.
If no header is found, then this will panic.
sourcepub fn iter_headers<'a>(
&'a self
) -> impl Iterator<Item = (&'a HeaderName, &'a HeaderValue)>
pub fn iter_headers<'a>( &'a self ) -> impl Iterator<Item = (&'a HeaderName, &'a HeaderValue)>
Iterates over all of the headers contained in the response.
sourcepub fn iter_headers_by_name<'a, N>(
&'a self,
header_name: N
) -> impl Iterator<Item = &'a HeaderValue>where
N: AsHeaderName,
pub fn iter_headers_by_name<'a, N>( &'a self, header_name: N ) -> impl Iterator<Item = &'a HeaderValue>where N: AsHeaderName,
Iterates over all of the headers for a specific name, contained in the response.
Returns all of the cookies contained in the response,
within a CookieJar object.
See the cookie crate for details.
Iterate over all of the cookies in 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.
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