pub struct TestServer<S> { /* private fields */ }Expand description
Test server for integration testing.
This server is single-threaded by design — it holds a single &mut reference
to the underlying service and processes one request at a time. For concurrent
tests, create a separate TestServer per test function (the server is cheap to
construct).
§Example
ⓘ
use toxi_testing::{test_router, TestRequest};
#[tokio::test]
async fn test_hello() {
let mut server = test_router(my_router());
let req = TestRequest::get("/hello").build_toxi();
let resp = server.call(req).await.unwrap();
assert_eq!(resp.status(), 200);
}Implementations§
Source§impl<S> TestServer<S>
impl<S> TestServer<S>
Sourcepub async fn call(&mut self, request: ToxiRequest) -> Result<ToxiResponse>
pub async fn call(&mut self, request: ToxiRequest) -> Result<ToxiResponse>
Send a request to the test server.
Because the underlying Tower Service requires &mut self for ready(),
this method takes &mut self. If you need concurrent requests, either
clone the test server or construct a fresh one per concurrent task.
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for TestServer<S>where
S: Freeze,
impl<S> RefUnwindSafe for TestServer<S>where
S: RefUnwindSafe,
impl<S> Send for TestServer<S>where
S: Send,
impl<S> Sync for TestServer<S>where
S: Sync,
impl<S> Unpin for TestServer<S>where
S: Unpin,
impl<S> UnsafeUnpin for TestServer<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for TestServer<S>where
S: UnwindSafe,
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