Expand description
In-process testing: dispatch requests through the full protection /
router / middleware / handler path without binding a socket. This is
the foundation of nitr test and of Rust-level integration tests.
Also here, because they need crate-private types: the request options
nitr.test.request understands (TestRequest), the fake request and
the in-state application nitr test unit tests use (fake_request,
load_app), the server-sent-events parser behind resp:sse()
(parse_sse), and the watcher behind nitr test --watch.
Structs§
- Handler
Failure - Why a request answered with the error path: the classified failure the
handler raised, and whether the application’s
on_errorproduced the response. - SseEvent
- One dispatched server-sent event.
- Test
Client - An in-process client for a built
Server; obtained viaServer::test_client(). - Test
Request - One test request: what
TestClient::senddispatches. - Test
Response - A fully collected response from
TestClient::request. - Test
Watch - Keeps the
nitr test --watchwatcher alive; dropping it stops the watcher thread.
Functions§
- fake_
request - Builds a request userdata for a unit test (
t.fake_request(spec)): the same type a handler receives, soreq.*,req:json(),nitr.session(req, ...),nitr.csrf.token(req)andnitr.auth.*behave as in production. - fixture_
path - Resolves a fixture file a test names (
t.db.seed("fixtures/x.sql")) underroot, the tests directory: the static server’s lexical rule (no.., no absolute path, no NUL), then canonical containment, and it must be a regular file. - load_
app - Compiles the application into this state and returns the object
t.app()hands a test. - parse_
sse - Parses a whole event-stream body into its events, in order.
- watch_
tests - Watches what
nitr devwatches (the handler’s directory, the configuration script, the templates) plusextra(the tests directory), sending onchangedafter each debounced burst of changes to a Lua source or a template.Nonewhen there is nothing to watch or the platform watcher is unavailable.