pub struct TestResponse { /* private fields */ }Expand description
Test response wrapper
Implementations§
Source§impl TestResponse
impl TestResponse
Sourcepub async fn new(response: Response<Full<Bytes>>) -> Self
pub async fn new(response: Response<Full<Bytes>>) -> Self
Create a new test response (async version for collecting body)
§Examples
use reinhardt_testkit::response::TestResponse;
use http::{Response, StatusCode};
use http_body_util::Full;
use bytes::Bytes;
let response = Response::builder()
.status(StatusCode::OK)
.body(Full::new(Bytes::from("Hello World")))
.unwrap();
let test_response = TestResponse::new(response).await;
assert_eq!(test_response.status(), StatusCode::OK);Sourcepub fn with_body(status: StatusCode, headers: HeaderMap, body: Bytes) -> Self
pub fn with_body(status: StatusCode, headers: HeaderMap, body: Bytes) -> Self
Create a test response with status, headers, and body (defaults to HTTP/1.1)
Sourcepub fn with_body_and_version(
status: StatusCode,
headers: HeaderMap,
body: Bytes,
version: Version,
) -> Self
pub fn with_body_and_version( status: StatusCode, headers: HeaderMap, body: Bytes, version: Version, ) -> Self
Create a test response with status, headers, body, and HTTP version
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get response status
Sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
Get response status code as u16
Sourcepub fn version(&self) -> Version
pub fn version(&self) -> Version
Get HTTP version of the response
§Examples
use reinhardt_testkit::response::TestResponse;
use http::{StatusCode, HeaderMap, Version};
use bytes::Bytes;
let response = TestResponse::with_body_and_version(
StatusCode::OK,
HeaderMap::new(),
Bytes::new(),
Version::HTTP_2,
);
assert_eq!(response.version(), Version::HTTP_2);Sourcepub fn json<T: DeserializeOwned>(&self) -> Result<T, Error>
pub fn json<T: DeserializeOwned>(&self) -> Result<T, Error>
Parse response body as JSON
Sourcepub fn json_value(&self) -> Result<Value, Error>
pub fn json_value(&self) -> Result<Value, Error>
Parse response body as generic JSON value
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if response is successful (2xx)
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if response is client error (4xx)
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Check if response is server error (5xx)
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Get content type header
Trait Implementations§
Source§impl ResponseExt for TestResponse
impl ResponseExt for TestResponse
Source§fn assert_status(&self, expected: StatusCode) -> &Self
fn assert_status(&self, expected: StatusCode) -> &Self
Assert status code
Source§fn assert_success(&self) -> &Self
fn assert_success(&self) -> &Self
Assert 2xx success
Source§fn assert_client_error(&self) -> &Self
fn assert_client_error(&self) -> &Self
Assert 4xx client error
Source§fn assert_server_error(&self) -> &Self
fn assert_server_error(&self) -> &Self
Assert 5xx server error
Source§fn assert_created(&self) -> &Self
fn assert_created(&self) -> &Self
Assert that the response status is 201 Created.
Source§fn assert_no_content(&self) -> &Self
fn assert_no_content(&self) -> &Self
Assert that the response status is 204 No Content.
Source§fn assert_bad_request(&self) -> &Self
fn assert_bad_request(&self) -> &Self
Assert that the response status is 400 Bad Request.
Assert that the response status is 401 Unauthorized.
Source§fn assert_forbidden(&self) -> &Self
fn assert_forbidden(&self) -> &Self
Assert that the response status is 403 Forbidden.
Source§fn assert_not_found(&self) -> &Self
fn assert_not_found(&self) -> &Self
Assert that the response status is 404 Not Found.
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more