test: Add test for WsConnection for ping response (#1619)

This commit is contained in:
Sergey Kuznetsov
2024-09-05 16:33:04 +01:00
parent 443c74436e
commit b7449f72b7
3 changed files with 69 additions and 0 deletions

View File

@@ -75,6 +75,14 @@ TestWsConnection::send(std::string const& message, boost::asio::yield_context yi
return std::nullopt;
}
void
TestWsConnection::sendPing(boost::beast::websocket::ping_data const& data, boost::asio::yield_context yield)
{
boost::beast::error_code errorCode;
ws_.async_ping(data, yield[errorCode]);
[&]() { ASSERT_FALSE(errorCode) << errorCode.message(); }();
}
std::optional<std::string>
TestWsConnection::receive(boost::asio::yield_context yield)
{
@@ -105,6 +113,20 @@ TestWsConnection::headers() const
return headers_;
}
void
TestWsConnection::setControlFrameCallback(
std::function<void(boost::beast::websocket::frame_type, std::string_view)> callback
)
{
ws_.control_callback(std::move(callback));
}
void
TestWsConnection::resetControlFrameCallback()
{
ws_.control_callback();
}
TestWsServer::TestWsServer(asio::io_context& context, std::string const& host) : acceptor_(context)
{
auto endpoint = asio::ip::tcp::endpoint(boost::asio::ip::make_address(host), 0);