How test_client reaches the app: in memory (the default) or over a loopback socket, whether redirects are followed, and the
timeout of a request.
go_home :: () -> Response {
return redirect("/home");
}
home :: () -> string {
return "home";
}
main :: () {
app: App;
defer free_app(*app);
get(*app, "/", go_home);
get(*app, "/home", home);
plain := test_client(*app);
first, _ := get(plain, "/");
assert(first.status == 302); // the default hands the redirect back
close(*first);
following := test_client(*app, .{ follow_redirects = true });
second, _ := get(following, "/");
assert(second.status == 200);
close(*second);
}Doesn't run in the browser (skipped on wasm).
Fields
- over_tcp: := false
- Serve the app on a loopback socket (a free port, started on first use) instead of in
memory. This sets
app.config.addressand turnshandle_signalsoff. - follow_redirects: := false
- Follow redirects like the real client. Off, a 3xx is the response, so it can be checked
(
expect_redirect);send(api, .{ url = ..., max_redirects = 5 })follows for one request. - timeout: := 10_000
- Milliseconds a request may take before it fails with
.TIMED_OUT(the client'stimeout).