Компиляция последнего теста контроллера

This commit is contained in:
Антон
2025-08-24 08:14:24 +03:00
parent 823c6ccfe9
commit d53814c3cc
2 changed files with 43 additions and 2 deletions
+7
View File
@@ -9,7 +9,14 @@ namespace uad
template <class Body, class Allocator, class ResponseType> template <class Body, class Allocator, class ResponseType>
class Controller : IController<Body, Allocator, ResponseType> class Controller : IController<Body, Allocator, ResponseType>
{ {
using HTTPMethodsToExecutors = std::unordered_map<boost::beast::http::verb, std::unique_ptr<IExecutor<Body, Allocator, ResponseType>>>;
HTTPMethodsToExecutors executors_;
public: public:
Controller() = default;
explicit Controller(HTTPMethodsToExecutors&& executors) {}
std::optional<std::unique_ptr<IExecutor<Body, Allocator, ResponseType>>> FindExecutor( std::optional<std::unique_ptr<IExecutor<Body, Allocator, ResponseType>>> FindExecutor(
boost::beast::http::verb method boost::beast::http::verb method
) const override ) const override
+35 -1
View File
@@ -15,11 +15,27 @@ using namespace boost;
using namespace std; using namespace std;
using namespace uad; using namespace uad;
class MockExecutor : public IExecutor<beast::http::string_body,
std::allocator<char>,
beast::http::string_body>
{
public:
beast::http::response<beast::http::string_body> operator ()(
beast::http::request<beast::http::string_body, beast::http::basic_fields<std::allocator<char>>>&& req
) override
{
boost::beast::http::response<boost::beast::http::string_body> res{
boost::beast::http::status::not_found, req.version()};
return res;
}
};
BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_No_Executors) BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_No_Executors)
{ {
Controller<beast::http::string_body, Controller<beast::http::string_body,
std::allocator<char>, std::allocator<char>,
beast::http::response<beast::http::string_body>> my_controller; beast::http::string_body> my_controller;
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::get).has_value()); BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::get).has_value());
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::post).has_value()); BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::post).has_value());
@@ -28,3 +44,21 @@ BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_No_Executors)
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::head).has_value()); BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::head).has_value());
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::options).has_value()); BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::options).has_value());
} }
BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_Unordered_Map_HTTP_Methods_To_Executors)
{
std::unordered_map<boost::beast::http::verb, std::unique_ptr<IExecutor<beast::http::string_body, std::allocator<char>, beast::http::string_body>>> executors;
executors[beast::http::verb::get] = make_unique<MockExecutor>();
Controller<beast::http::string_body,
std::allocator<char>,
beast::http::string_body> my_controller(std::move(executors));
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::get).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::post).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::put).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::delete_).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::head).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::options).has_value());
}