|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
orbit::testing::Client calls an application's routes in-process: no listen(), no ports, no sockets. Tests run in milliseconds and never collide on a port.
The request goes through the same router as on the network: global, prefix and group middleware, routing (including 404 and 405 with Allow), on_error handlers, not_found, sessions and anything a middleware adds to the response. What the network layer itself adds (Date, Content-Length framing, HTTP/2) is not applied.
send(timeout) waits until the response is complete, five seconds by default. An application error is a response, never an exception: a 500, or whatever on_error answers.
Response has status, headers (look them up with header("name"), case insensitive), body, json(), cookies (the Set-Cookie entries) and, for streamed responses, chunks.
The client keeps a cookie jar (client.cookies()): cookies the application sets are sent with later requests, so a login followed by an authenticated request works as in a browser. Use a second Client for a second user.
Handlers that co_await work as they do in the server. The client runs a small thread pool and an event loop of its own, which writer->thread_pool() and writer->proactor() return, and send() waits for the response however it arrives.
Chunks from write_chunk() and events from send_sse_event() are collected in chunks, already in wire format ("event: update\nid: 2\ndata: two\n\n"). A stream that never ends (a live SSE feed) returns when send()'s timeout passes, with complete == false and what was sent so far:
When send() returns, the "client" leaves: a writer the application kept reports is_open() == false and runs its on_close() callbacks, as if the browser had closed the tab.
WebSocket upgrades and raw streams (upgrade_to_raw_stream). Test those against a running server, as tests/integration does.