Files
weaseldb/tests/test_http_handler.cpp

61 lines
1.7 KiB
C++

#include "arena.hpp"
#include "http_handler.hpp"
#include "perfetto_categories.hpp"
#include <atomic>
#include <doctest/doctest.h>
// Perfetto static storage for tests
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
// Global variable needed by Connection
std::atomic<int> activeConnections{0};
// Simple test helper since Connection has complex constructor requirements
struct TestConnectionData {
Arena arena;
std::string message_buffer;
void *user_data = nullptr;
void append_message(std::string_view data) { message_buffer += data; }
Arena &get_arena() { return arena; }
const std::string &getResponse() const { return message_buffer; }
void clearResponse() { message_buffer.clear(); }
void reset() {
arena.reset();
message_buffer.clear();
}
};
// Test helper to verify the new hook functionality
struct MockConnectionHandler : public ConnectionHandler {
bool write_progress_called = false;
bool write_buffer_drained_called = false;
void on_write_progress(std::unique_ptr<Connection> &) override {
write_progress_called = true;
}
void on_write_buffer_drained(std::unique_ptr<Connection> &) override {
write_buffer_drained_called = true;
}
};
TEST_CASE("ConnectionHandler hooks") {
SUBCASE("on_write_buffer_drained hook exists") {
MockConnectionHandler handler;
// Verify hooks are available and can be overridden
CHECK_FALSE(handler.write_progress_called);
CHECK_FALSE(handler.write_buffer_drained_called);
// Would normally be called by Server during write operations
std::unique_ptr<Connection> null_conn;
handler.on_write_progress(null_conn);
handler.on_write_buffer_drained(null_conn);
CHECK(handler.write_progress_called);
CHECK(handler.write_buffer_drained_called);
}
}