comparison tests/plugin-load-command/main.cpp @ 579:84ea13c850f4

Tests: rename close to target names
author David Demelier <markand@malikania.fr>
date Mon, 04 Dec 2017 13:49:51 +0100
parents tests/cmd-plugin-load/main.cpp@153e84e7b09b
children
comparison
equal deleted inserted replaced
578:a8b892177909 579:84ea13c850f4
1 /*
2 * main.cpp -- test plugin-load 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-load"
20 #include <boost/test/unit_test.hpp>
21
22 #include <irccd/command.hpp>
23 #include <irccd/plugin_service.hpp>
24
25 #include <command_test.hpp>
26
27 namespace irccd {
28
29 namespace {
30
31 class custom_loader : public plugin_loader {
32 public:
33 std::shared_ptr<plugin> open(const std::string&,
34 const std::string&) noexcept override
35 {
36 return nullptr;
37 }
38
39 std::shared_ptr<plugin> find(const std::string& id) noexcept override
40 {
41 class broken : public plugin {
42 public:
43 using plugin::plugin;
44
45 void on_load(irccd&) override
46 {
47 throw std::runtime_error("broken");
48 }
49 };
50
51 /*
52 * The 'magic' plugin will be created for the unit tests, all other
53 * plugins will return null.
54 */
55 if (id == "magic")
56 return std::make_unique<plugin>(id, "");
57 if (id == "broken")
58 return std::make_unique<broken>(id, "");
59
60 return nullptr;
61 }
62 };
63
64 class plugin_load_test : public command_test<plugin_load_command> {
65 public:
66 plugin_load_test()
67 {
68 daemon_->plugins().add_loader(std::make_unique<custom_loader>());
69 daemon_->plugins().add(std::make_unique<plugin>("already", ""));
70 }
71 };
72
73 } // !namespace
74
75 BOOST_FIXTURE_TEST_SUITE(plugin_load_test_suite, plugin_load_test)
76
77 BOOST_AUTO_TEST_CASE(basic)
78 {
79 ctl_->send({
80 { "command", "plugin-load" },
81 { "plugin", "magic" }
82 });
83
84 wait_for([&] () {
85 return daemon_->plugins().has("magic");
86 });
87
88 BOOST_TEST(!daemon_->plugins().list().empty());
89 BOOST_TEST(daemon_->plugins().has("magic"));
90 }
91
92 BOOST_AUTO_TEST_SUITE(errors)
93
94 BOOST_AUTO_TEST_CASE(not_found)
95 {
96 boost::system::error_code result;
97
98 ctl_->send({
99 { "command", "plugin-load" },
100 { "plugin", "unknown" }
101 });
102 ctl_->recv([&] (auto code, auto) {
103 result = code;
104 });
105
106 wait_for([&] {
107 return result;
108 });
109
110 BOOST_ASSERT(result == plugin_error::not_found);
111 }
112
113 BOOST_AUTO_TEST_CASE(already_exists)
114 {
115 boost::system::error_code result;
116
117 ctl_->send({
118 { "command", "plugin-load" },
119 { "plugin", "already" }
120 });
121 ctl_->recv([&] (auto code, auto) {
122 result = code;
123 });
124
125 wait_for([&] {
126 return result;
127 });
128
129 BOOST_ASSERT(result == plugin_error::already_exists);
130 }
131
132 BOOST_AUTO_TEST_CASE(exec_error)
133 {
134 boost::system::error_code result;
135
136 ctl_->send({
137 { "command", "plugin-load" },
138 { "plugin", "broken" }
139 });
140 ctl_->recv([&] (auto code, auto) {
141 result = code;
142 });
143
144 wait_for([&] {
145 return result;
146 });
147
148 BOOST_ASSERT(result == plugin_error::exec_error);
149 }
150
151 BOOST_AUTO_TEST_SUITE_END()
152
153 BOOST_AUTO_TEST_SUITE_END()
154
155 } // !irccd