Mercurial > irccd
comparison tests/src/libirccd/command-plugin-config/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-config-command/main.cpp@22b3cd6f991f |
children | f69b1faf812f |
comparison
equal
deleted
inserted
replaced
610:22b3cd6f991f | 611:9fbd1700435b |
---|---|
1 /* | |
2 * main.cpp -- test plugin-config 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-config" | |
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 namespace { | |
30 | |
31 class custom_plugin : public plugin { | |
32 public: | |
33 plugin_config config_; | |
34 | |
35 custom_plugin(std::string name = "test") | |
36 : plugin(std::move(name), "") | |
37 { | |
38 } | |
39 | |
40 plugin_config config() override | |
41 { | |
42 return config_; | |
43 } | |
44 | |
45 void set_config(plugin_config config) override | |
46 { | |
47 config_ = std::move(config); | |
48 } | |
49 }; | |
50 | |
51 } // !namespace | |
52 | |
53 BOOST_FIXTURE_TEST_SUITE(plugin_config_test_suite, command_test<plugin_config_command>) | |
54 | |
55 BOOST_AUTO_TEST_CASE(set) | |
56 { | |
57 daemon_->plugins().add(std::make_unique<custom_plugin>("test")); | |
58 ctl_->send({ | |
59 { "command", "plugin-config" }, | |
60 { "plugin", "test" }, | |
61 { "variable", "verbosy" }, | |
62 { "value", "falsy" } | |
63 }); | |
64 | |
65 wait_for([&] { | |
66 return !daemon_->plugins().require("test")->config().empty(); | |
67 }); | |
68 | |
69 auto config = daemon_->plugins().require("test")->config(); | |
70 | |
71 BOOST_TEST(!config.empty()); | |
72 BOOST_TEST(config["verbosy"] == "falsy"); | |
73 } | |
74 | |
75 BOOST_AUTO_TEST_CASE(get) | |
76 { | |
77 auto plugin = std::make_unique<custom_plugin>("test"); | |
78 auto json = nlohmann::json(); | |
79 | |
80 plugin->set_config({ | |
81 { "x1", "10" }, | |
82 { "x2", "20" } | |
83 }); | |
84 | |
85 daemon_->plugins().add(std::move(plugin)); | |
86 ctl_->send({ | |
87 { "command", "plugin-config" }, | |
88 { "plugin", "test" }, | |
89 { "variable", "x1" } | |
90 }); | |
91 ctl_->recv([&] (auto, auto message) { | |
92 json = std::move(message); | |
93 }); | |
94 | |
95 wait_for([&] { | |
96 return json.is_object(); | |
97 }); | |
98 | |
99 BOOST_TEST(json.is_object()); | |
100 BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); | |
101 BOOST_TEST(json["variables"]["x2"].is_null()); | |
102 } | |
103 | |
104 BOOST_AUTO_TEST_CASE(getall) | |
105 { | |
106 auto plugin = std::make_unique<custom_plugin>("test"); | |
107 auto json = nlohmann::json(); | |
108 | |
109 plugin->set_config({ | |
110 { "x1", "10" }, | |
111 { "x2", "20" } | |
112 }); | |
113 | |
114 daemon_->plugins().add(std::move(plugin)); | |
115 ctl_->send({ | |
116 { "command", "plugin-config" }, | |
117 { "plugin", "test" } | |
118 }); | |
119 ctl_->recv([&] (auto, auto message) { | |
120 json = std::move(message); | |
121 }); | |
122 | |
123 wait_for([&] { | |
124 return json.is_object(); | |
125 }); | |
126 | |
127 BOOST_TEST(json.is_object()); | |
128 BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); | |
129 BOOST_TEST(json["variables"]["x2"].get<std::string>() == "20"); | |
130 } | |
131 | |
132 BOOST_AUTO_TEST_SUITE(errors) | |
133 | |
134 BOOST_AUTO_TEST_CASE(not_found) | |
135 { | |
136 boost::system::error_code result; | |
137 nlohmann::json message; | |
138 | |
139 ctl_->send({ | |
140 { "command", "plugin-config" }, | |
141 { "plugin", "unknown" } | |
142 }); | |
143 ctl_->recv([&] (auto rresult, auto rmessage) { | |
144 result = rresult; | |
145 message = rmessage; | |
146 }); | |
147 | |
148 wait_for([&] { | |
149 return result; | |
150 }); | |
151 | |
152 BOOST_TEST(result == plugin_error::not_found); | |
153 BOOST_TEST(message["error"].template get<int>() == plugin_error::not_found); | |
154 BOOST_TEST(message["errorCategory"].template get<std::string>() == "plugin"); | |
155 } | |
156 | |
157 BOOST_AUTO_TEST_SUITE_END() | |
158 | |
159 BOOST_AUTO_TEST_SUITE_END() | |
160 | |
161 } // !irccd |