Mercurial > irccd
diff tests/src/libirccd/command-plugin-info/main.cpp @ 651:1081e45b8628
Tests: use command_test::request helper, closes #784 @1h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 27 Mar 2018 20:12:02 +0200 |
parents | 7e2d0739f37c |
children | 3e816cebed2c |
line wrap: on
line diff
--- a/tests/src/libirccd/command-plugin-info/main.cpp Mon Mar 26 20:46:02 2018 +0200 +++ b/tests/src/libirccd/command-plugin-info/main.cpp Tue Mar 27 20:12:02 2018 +0200 @@ -37,72 +37,42 @@ plg->set_license("GPL"); plg->set_summary("Completely useless plugin"); plg->set_version("0.0.0.0.0.0.0.0.1-beta5"); + daemon_->plugins().add(std::move(plg)); - daemon_->plugins().add(std::move(plg)); - ctl_->recv([&] (auto, auto msg) { - response = std::move(msg); - }); - ctl_->send({ + const auto result = request({ { "command", "plugin-info" }, { "plugin", "test" }, }); - wait_for([&] () { - return response.is_object(); - }); - - BOOST_TEST(response.is_object()); - BOOST_TEST(response["author"].get<std::string>() == "Francis Beaugrand"); - BOOST_TEST(response["license"].get<std::string>() == "GPL"); - BOOST_TEST(response["summary"].get<std::string>() == "Completely useless plugin"); - BOOST_TEST(response["version"].get<std::string>() == "0.0.0.0.0.0.0.0.1-beta5"); + BOOST_TEST(result.first["author"].get<std::string>() == "Francis Beaugrand"); + BOOST_TEST(result.first["license"].get<std::string>() == "GPL"); + BOOST_TEST(result.first["summary"].get<std::string>() == "Completely useless plugin"); + BOOST_TEST(result.first["version"].get<std::string>() == "0.0.0.0.0.0.0.0.1-beta5"); } BOOST_AUTO_TEST_SUITE(errors) BOOST_AUTO_TEST_CASE(invalid_identifier) { - boost::system::error_code result; - nlohmann::json message; - - ctl_->send({ + const auto result = request({ { "command", "plugin-info" } }); - ctl_->recv([&] (auto rresult, auto rmessage) { - result = rresult; - message = rmessage; - }); - wait_for([&] { - return result; - }); - - BOOST_TEST(result == plugin_error::invalid_identifier); - BOOST_TEST(message["error"].template get<int>() == plugin_error::invalid_identifier); - BOOST_TEST(message["errorCategory"].template get<std::string>() == "plugin"); + BOOST_TEST(result.second == plugin_error::invalid_identifier); + BOOST_TEST(result.first["error"].template get<int>() == plugin_error::invalid_identifier); + BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "plugin"); } BOOST_AUTO_TEST_CASE(not_found) { - boost::system::error_code result; - nlohmann::json message; - - ctl_->send({ + const auto result = request({ { "command", "plugin-info" }, { "plugin", "unknown" } }); - ctl_->recv([&] (auto rresult, auto rmessage) { - result = rresult; - message = rmessage; - }); - wait_for([&] { - return result; - }); - - BOOST_TEST(result == plugin_error::not_found); - BOOST_TEST(message["error"].template get<int>() == plugin_error::not_found); - BOOST_TEST(message["errorCategory"].template get<std::string>() == "plugin"); + BOOST_TEST(result.second == plugin_error::not_found); + BOOST_TEST(result.first["error"].template get<int>() == plugin_error::not_found); + BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "plugin"); } BOOST_AUTO_TEST_SUITE_END()