pub struct TestRequest { /* private fields */ }
Expand description
A simpler version of Request
that is useful for testing. No data actually goes anywhere.
By default, TestRequest
pretends to be an insecure GET request for the server root (/
)
with no headers. To create a TestRequest
with different parameters, use the builder pattern:
let request = TestRequest::new()
.with_method(Method::Post)
.with_path("/api/widgets")
.with_body("42");
Then, convert the TestRequest
into a real Request
and pass it to the server under test:
let response = server.handle_request(request.into());
assert_eq!(response.status_code(), StatusCode(200));
Implementations§
Source§impl TestRequest
impl TestRequest
pub fn new() -> Self
pub fn with_body(self, body: &'static str) -> Self
pub fn with_remote_addr(self, remote_addr: SocketAddr) -> Self
pub fn with_https(self) -> Self
pub fn with_method(self, method: Method) -> Self
pub fn with_path(self, path: &str) -> Self
pub fn with_http_version(self, version: HTTPVersion) -> Self
pub fn with_header(self, header: Header) -> Self
Trait Implementations§
Source§impl Default for TestRequest
impl Default for TestRequest
Source§impl From<TestRequest> for Request
impl From<TestRequest> for Request
Source§fn from(mock: TestRequest) -> Request
fn from(mock: TestRequest) -> Request
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for TestRequest
impl RefUnwindSafe for TestRequest
impl Send for TestRequest
impl Sync for TestRequest
impl Unpin for TestRequest
impl UnwindSafe for TestRequest
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