#pragma once // Spec: SPEC.md NFR-TEST-01. A real aiohttpcpp web server on 127.0.0.1 with a random port, running on its own loop // thread. One catch-all route per method records each request and answers with the Reply the test handler returns. #include #include #include #include #include #include #include #include #include namespace dp::test { struct SeenRequest { std::string method; std::string path; std::string query; std::string authorization; std::string accept; std::string contentType; std::string body; }; struct Reply { int status = 200; std::string body; std::string contentType = "application/json"; double delaySeconds = 0.0; }; class TestServer { public: using Handler = std::function; explicit TestServer(Handler handler); ~TestServer(); TestServer(const TestServer&) = delete; TestServer& operator=(const TestServer&) = delete; int port() const { return port_; } std::string baseUrl() const { return "http://127.0.0.1:" + std::to_string(port_) + "/"; } std::vector seen() const; void clearSeen(); SeenRequest last() const; // Websocket route GET /messages/ws: sends `greeting` frames after the handshake, then (optionally) closes at once. void setWsGreeting(std::vector frames, bool closeAfterGreeting); int wsConnections() const; std::vector wsReceived() const; std::string wsLastQuery() const; struct Impl; private: std::unique_ptr impl_; int port_ = 0; }; } // namespace dp::test