trillium-testing-v0.8.0
·
191 commits
to main
since this release
Changed
- Compatible with trillium 1.0
init(&mut handler)is now async and returnsArc<HttpContext>:init(&mut handler).await; capture the returned value if you need to pass it toTestConn::with_context()ClientConfigstruct removed; use theclient_config()function orRuntimelessClientConfigdirectlySpawnHandle<F>removed; background task handles are nowDroppableFuturefromtrillium-server-common
Added
- Introduce new testing approach described at
TestHandler:
use trillium::{Conn, Status, conn_try};
use trillium_testing::TestServer;
async fn handler(mut conn: Conn) -> Conn {
let Ok(request_body) = conn.request_body_string().await else {
return conn.with_status(500).halt();
};
conn.with_body(format!("request body was: {}", request_body))
.with_status(418)
.with_response_header("request-id", "special-request")
}
let app = TestServer::new(handler).await;
app.post("/")
.with_body("hello trillium!")
.await
.assert_status(Status::ImATeapot)
.assert_body("request body was: hello trillium!")
.assert_headers([
("request-id", "special-request"),
("content-length", "33")
]);- The assertion macros (
assert_ok!,assert_status!,assert_not_handled!, etc.) and request builders are unchanged - Zero-dependency testing: when no runtime feature is enabled,
RuntimelessRuntime,RuntimelessServer, andRuntimelessClientConfigprovide fully in-memory test infrastructure without requiring tokio, smol, or async-std with_runtime(|runtime| async { ... })— test harness that injects aRuntimeinto the test closure, also usable as a test harnessTestConn::with_context(Arc<HttpContext>)— pass a server config (including shared state initialized byinit) to a test connection
Added
- (api) [breaking] make IoErrors respond with BadRequest
- deprecate set_state for insert_state
Other
- release