pub struct TestClient { /* private fields */ }Expand description
An in-process test client bound to an assembled App.
TestClient drives App::process directly — no socket is
bound and no runtime port is used — so tests are fast and hermetic. Build a
request with get / post /
put / delete (or the generic
request), then call
send to get a TestResponse.
use churust_core::{Churust, Call, TestClient};
let app = Churust::server()
.routing(|r| { r.get("/", |_c: Call| async { "home" }); })
.build();
let res = TestClient::new(app).get("/").send().await;
assert_eq!(res.status().as_u16(), 200);
assert_eq!(res.text(), "home");Implementations§
Source§impl TestClient
impl TestClient
Sourcepub fn request(&self, method: Method, uri: impl Into<String>) -> TestRequest<'_>
pub fn request(&self, method: Method, uri: impl Into<String>) -> TestRequest<'_>
Begin building a request with an arbitrary method and uri. The verb
helpers (get, post, etc.) call
this for the common methods.
use churust_core::{Churust, Call, TestClient};
use http::Method;
let app = Churust::server()
.routing(|r| { r.get("/", |_c: Call| async { "ok" }); })
.build();
let res = TestClient::new(app).request(Method::GET, "/").send().await;
assert_eq!(res.text(), "ok");Sourcepub fn get(&self, uri: impl Into<String>) -> TestRequest<'_>
pub fn get(&self, uri: impl Into<String>) -> TestRequest<'_>
Begin building a GET request to uri.
Sourcepub fn post(&self, uri: impl Into<String>) -> TestRequest<'_>
pub fn post(&self, uri: impl Into<String>) -> TestRequest<'_>
Begin building a POST request to uri.
Sourcepub fn put(&self, uri: impl Into<String>) -> TestRequest<'_>
pub fn put(&self, uri: impl Into<String>) -> TestRequest<'_>
Begin building a PUT request to uri.
Sourcepub fn delete(&self, uri: impl Into<String>) -> TestRequest<'_>
pub fn delete(&self, uri: impl Into<String>) -> TestRequest<'_>
Begin building a DELETE request to uri.
Auto Trait Implementations§
impl !RefUnwindSafe for TestClient
impl !UnwindSafe for TestClient
impl Freeze for TestClient
impl Send for TestClient
impl Sync for TestClient
impl Unpin for TestClient
impl UnsafeUnpin for TestClient
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