pub struct TestRequest<'c> { /* private fields */ }Expand description
A builder for a single in-process test request.
Created by the TestClient verb methods. Chain header
and body to refine the request, then await
send to run it through the pipeline.
Implementations§
Source§impl<'c> TestRequest<'c>
impl<'c> TestRequest<'c>
Sourcepub fn header(self, name: &'static str, value: &str) -> Self
pub fn header(self, name: &'static str, value: &str) -> Self
Set a request header, returning self for chaining.
§Panics
Panics if value is not a valid header value (this is a test helper, so
it favors a clear failure over a Result).
use churust_core::{Churust, Call, TestClient};
let app = Churust::server()
.routing(|r| {
r.get("/", |c: Call| async move {
c.header("x-test").unwrap_or("none").to_string()
});
})
.build();
let res = TestClient::new(app).get("/").header("x-test", "yes").send().await;
assert_eq!(res.text(), "yes");Sourcepub fn body(self, body: impl Into<Bytes>) -> Self
pub fn body(self, body: impl Into<Bytes>) -> Self
Set the request body, returning self for chaining.
use churust_core::{Churust, Call, TestClient};
let app = Churust::server()
.routing(|r| {
r.post("/echo", |mut c: Call| async move {
c.receive_text().await.unwrap_or_default()
});
})
.build();
let res = TestClient::new(app).post("/echo").body("ping").send().await;
assert_eq!(res.text(), "ping");Sourcepub async fn send(self) -> TestResponse
pub async fn send(self) -> TestResponse
Run the request through the application pipeline and return the
TestResponse, consuming the builder.
§Panics
Panics if the configured URI fails to parse.
Auto Trait Implementations§
impl<'c> !Freeze for TestRequest<'c>
impl<'c> !RefUnwindSafe for TestRequest<'c>
impl<'c> !UnwindSafe for TestRequest<'c>
impl<'c> Send for TestRequest<'c>
impl<'c> Sync for TestRequest<'c>
impl<'c> Unpin for TestRequest<'c>
impl<'c> UnsafeUnpin for TestRequest<'c>
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