Skip to main content

Module testing

Module testing 

Source
Expand description

Test doubles for nitr test: canned outbound responses and environment overrides, installed by a test as data and read by the standard library at the seams that honour them.

A test file and the server’s pooled states are separate Lua universes, so a double cannot be a Lua function patched into nitr.*: it would change the test’s state and nothing a handler sees. Instead the runner puts one Doubles into the app data of every state it builds — the pooled ones through ServerBuilder::setup, which also runs on a poison rebuild and a reload, and its own test state directly — and the setters live under nitr.test, which only the runner registers.

Absent app data means no double: that is the production path, and it costs each seam one app-data lookup. The types here are plain data, so the module compiles in every feature set even though the fetch seam exists only with fetch.

Structs§

Canned
The canned response a matched rule produced.
Doubles
Every double a test can install, shared by the test state and every pooled state of the server under test.
FetchCall
One outbound call made while the doubles were installed, whether a rule answered it or not.
FetchMock
Canned responses, the recorded calls, and the strict flag.
FetchRule
One canned answer for nitr.fetch.
MockedFailure
The failure a t.fetch.mock { error = ... } rule raises.

Enums§

FetchAnswer
What the double says about one outbound request.
UrlMatch
How a rule matches a request URL.

Constants§

MAX_RECORDED_CALLS
How many outbound calls a test records before the oldest are dropped: a chatty handler must not grow the record without bound.

Functions§

session_cookie_value
The value session:save would write for data: the JSON payload (with the expiry when max_age is set) signed for name — so a test can put a session into a client’s jar without a login round trip.