comparison tests/src/libirccd/command-plugin-info/main.cpp @ 611:9fbd1700435b

Tests: reoganize hierarchy
author David Demelier <markand@malikania.fr>
date Fri, 15 Dec 2017 15:37:58 +0100
parents tests/src/plugin-info-command/main.cpp@22b3cd6f991f
children f69b1faf812f
comparison
equal deleted inserted replaced
610:22b3cd6f991f 611:9fbd1700435b
1 /*
2 * main.cpp -- test plugin-info remote command
3 *
4 * Copyright (c) 2013-2017 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #define BOOST_TEST_MODULE "plugin-info"
20 #include <boost/test/unit_test.hpp>
21
22 #include <irccd/daemon/command.hpp>
23 #include <irccd/daemon/plugin_service.hpp>
24
25 #include <irccd/test/command_test.hpp>
26
27 namespace irccd {
28
29 BOOST_FIXTURE_TEST_SUITE(plugin_info_test_suite, command_test<plugin_info_command>)
30
31 BOOST_AUTO_TEST_CASE(basic)
32 {
33 auto plg = std::make_unique<plugin>("test", "");
34 auto response = nlohmann::json();
35
36 plg->set_author("Francis Beaugrand");
37 plg->set_license("GPL");
38 plg->set_summary("Completely useless plugin");
39 plg->set_version("0.0.0.0.0.0.0.0.1-beta5");
40
41 daemon_->plugins().add(std::move(plg));
42 ctl_->recv([&] (auto, auto msg) {
43 response = std::move(msg);
44 });
45 ctl_->send({
46 { "command", "plugin-info" },
47 { "plugin", "test" },
48 });
49
50 wait_for([&] () {
51 return response.is_object();
52 });
53
54 BOOST_TEST(response.is_object());
55 BOOST_TEST(response["author"].get<std::string>() == "Francis Beaugrand");
56 BOOST_TEST(response["license"].get<std::string>() == "GPL");
57 BOOST_TEST(response["summary"].get<std::string>() == "Completely useless plugin");
58 BOOST_TEST(response["version"].get<std::string>() == "0.0.0.0.0.0.0.0.1-beta5");
59 }
60
61 BOOST_AUTO_TEST_SUITE(errors)
62
63 BOOST_AUTO_TEST_CASE(not_found)
64 {
65 boost::system::error_code result;
66 nlohmann::json message;
67
68 ctl_->send({
69 { "command", "plugin-info" },
70 { "plugin", "unknown" }
71 });
72 ctl_->recv([&] (auto rresult, auto rmessage) {
73 result = rresult;
74 message = rmessage;
75 });
76
77 wait_for([&] {
78 return result;
79 });
80
81 BOOST_TEST(result == plugin_error::not_found);
82 BOOST_TEST(message["error"].template get<int>() == plugin_error::not_found);
83 BOOST_TEST(message["errorCategory"].template get<std::string>() == "plugin");
84 }
85
86 BOOST_AUTO_TEST_SUITE_END()
87
88 BOOST_AUTO_TEST_SUITE_END()
89
90 } // !irccd