Expand description
testing utilities for trillium applications.
this crate is intended to be used as a development dependency.
use trillium_testing::prelude::*;
use trillium::{Conn, conn_try};
async fn handler(mut conn: Conn) -> Conn {
let request_body = conn_try!(conn.request_body_string().await, conn);
conn.with_body(format!("request body was: {}", request_body))
.with_status(418)
.with_response_header("request-id", "special-request")
}
assert_response!(
post("/").with_request_body("hello trillium!").on(&handler),
Status::ImATeapot,
"request body was: hello trillium!",
"request-id" => "special-request",
"content-length" => "33"
);
§Features
You must enable a runtime feature for trillium testing
§Tokio:
[dev-dependencies]
# ...
trillium-testing = { version = "0.2", features = ["tokio"] }
§Async-std:
[dev-dependencies]
# ...
trillium-testing = { version = "0.2", features = ["async-std"] }
§Smol:
[dev-dependencies]
# ...
trillium-testing = { version = "0.2", features = ["smol"] }
Re-exports§
pub use futures_lite;
Modules§
Macros§
- assert_
body - assert that the response body is as specified. this assertion requires mutation of the conn.
- assert_
body_ contains - asserts that the response body matches the specified pattern, using
str::contains
- assert_
headers - asserts any number of response headers
- assert_
not_ handled - assert that all of the following are true:
- assert_
ok - assert_ok is like
assert_response!
except it always asserts a status of 200 Ok. - assert_
response - combines several other assertions. this assertion can be used to assert:
- assert_
status - assert that the status code of a conn is as specified.
Structs§
- Client
Config - configuration for the tcp Connector
- Runtimeless
Client Config - An in-memory Connector to use with GenericServer.
- Runtimeless
Server - A
Server
for testing that does not depend on any runtime - Server
Connector - a bridge between trillium servers and clients
- Server
Handle - A handle for a spawned trillium server. Returned by
[
Config::handle
][crate::Config::handle] and [Config::spawn
][crate::Config::spawn] - Spawn
Handle - A droppable future
- Test
Conn - A wrapper around a
trillium::Conn
for testing - Test
Transport - a readable and writable transport for testing
- Url
- A parsed URL record.
Enums§
Traits§
- Async
Read - Read bytes asynchronously.
- Async
Read Ext - Extension trait for
AsyncRead
. - Async
Write - Write bytes asynchronously.
- Connector
- Interface for runtime and tls adapters for the trillium client
- Object
Safe Connector - Server
- The server trait, for standard network-based server implementations.
Functions§
- block_
on - Runs the global and the local executor on the current thread
- client_
config - runtime client config
- config
- runtime server config
- connector
- build a connector from this handler
- harness
- a test harness for use with [
test_harness
] - init
- initialize a handler
- spawn
- smol-based spawn variant that finishes whether or not the returned future is dropped
- with_
server - Starts a trillium handler bound to a random available port on localhost, run the async tests provided as the second argument, and then shut down the server. useful for full integration tests that actually exercise the tcp layer.
- with_
transport - open an in-memory connection to this handler and call an async function with an open BoxedTransport
Type Aliases§
- Test
Result - a sponge Result