Mercurial > irccd
comparison tests/src/rule-remove-command/main.cpp @ 581:a51b5dd5b761
Tests: put everything in src/
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 04 Dec 2017 14:12:13 +0100 |
parents | tests/rule-remove-command/main.cpp@84ea13c850f4 |
children | 029667d16d12 |
comparison
equal
deleted
inserted
replaced
580:2e16c3623531 | 581:a51b5dd5b761 |
---|---|
1 /* | |
2 * main.cpp -- test rule-remove 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 "rule-remove" | |
20 #include <boost/test/unit_test.hpp> | |
21 | |
22 #include <irccd/json_util.hpp> | |
23 | |
24 #include <irccd/command.hpp> | |
25 #include <irccd/rule_service.hpp> | |
26 | |
27 #include <command_test.hpp> | |
28 | |
29 namespace irccd { | |
30 | |
31 namespace { | |
32 | |
33 class rule_remove_test : public command_test<rule_remove_command> { | |
34 public: | |
35 rule_remove_test() | |
36 { | |
37 daemon_->commands().add(std::make_unique<rule_list_command>()); | |
38 daemon_->rules().add(rule( | |
39 { "s1", "s2" }, | |
40 { "c1", "c2" }, | |
41 { "o1", "o2" }, | |
42 { "p1", "p2" }, | |
43 { "onMessage", "onCommand" }, | |
44 rule::action_type::drop | |
45 )); | |
46 daemon_->rules().add(rule( | |
47 { "s1", }, | |
48 { "c1", }, | |
49 { "o1", }, | |
50 { "p1", }, | |
51 { "onMessage", }, | |
52 rule::action_type::accept | |
53 )); | |
54 } | |
55 }; | |
56 | |
57 } // !namespace | |
58 | |
59 BOOST_FIXTURE_TEST_SUITE(rule_remove_test_suite, rule_remove_test) | |
60 | |
61 BOOST_AUTO_TEST_CASE(basic) | |
62 { | |
63 nlohmann::json result; | |
64 | |
65 ctl_->send({ | |
66 { "command", "rule-remove" }, | |
67 { "index", 1 } | |
68 }); | |
69 ctl_->recv([&] (auto, auto msg) { | |
70 result = msg; | |
71 }); | |
72 | |
73 wait_for([&] () { | |
74 return result.is_object(); | |
75 }); | |
76 | |
77 BOOST_TEST(result.is_object()); | |
78 | |
79 result = nullptr; | |
80 ctl_->send({{ "command", "rule-list" }}); | |
81 ctl_->recv([&] (auto, auto msg) { | |
82 result = msg; | |
83 }); | |
84 | |
85 wait_for([&] () { | |
86 return result.is_object(); | |
87 }); | |
88 | |
89 BOOST_TEST(result["list"].is_array()); | |
90 BOOST_TEST(result["list"].size() == 1U); | |
91 | |
92 auto servers = result["list"][0]["servers"]; | |
93 auto channels = result["list"][0]["channels"]; | |
94 auto plugins = result["list"][0]["plugins"]; | |
95 auto events = result["list"][0]["events"]; | |
96 | |
97 BOOST_TEST(json_util::contains(servers, "s1")); | |
98 BOOST_TEST(json_util::contains(servers, "s2")); | |
99 BOOST_TEST(json_util::contains(channels, "c1")); | |
100 BOOST_TEST(json_util::contains(channels, "c2")); | |
101 BOOST_TEST(json_util::contains(plugins, "p1")); | |
102 BOOST_TEST(json_util::contains(plugins, "p2")); | |
103 BOOST_TEST(json_util::contains(events, "onMessage")); | |
104 BOOST_TEST(json_util::contains(events, "onCommand")); | |
105 BOOST_TEST(result["list"][0]["action"].get<std::string>() == "drop"); | |
106 } | |
107 | |
108 BOOST_AUTO_TEST_CASE(empty) | |
109 { | |
110 nlohmann::json result; | |
111 | |
112 daemon_->rules().remove(0); | |
113 daemon_->rules().remove(0); | |
114 | |
115 ctl_->send({ | |
116 { "command", "rule-remove" }, | |
117 { "index", 1 } | |
118 }); | |
119 ctl_->recv([&] (auto, auto msg) { | |
120 result = msg; | |
121 }); | |
122 | |
123 wait_for([&] () { | |
124 return result.is_object(); | |
125 }); | |
126 | |
127 BOOST_TEST(result.is_object()); | |
128 } | |
129 | |
130 BOOST_AUTO_TEST_SUITE(errors) | |
131 | |
132 BOOST_AUTO_TEST_CASE(invalid_index_1) | |
133 { | |
134 boost::system::error_code result; | |
135 | |
136 ctl_->send({ | |
137 { "command", "rule-remove" }, | |
138 { "index", -100 } | |
139 }); | |
140 ctl_->recv([&] (auto code, auto) { | |
141 result = code; | |
142 }); | |
143 | |
144 wait_for([&] { | |
145 return result; | |
146 }); | |
147 | |
148 BOOST_ASSERT(result == rule_error::invalid_index); | |
149 } | |
150 | |
151 BOOST_AUTO_TEST_CASE(invalid_index_2) | |
152 { | |
153 boost::system::error_code result; | |
154 | |
155 ctl_->send({ | |
156 { "command", "rule-remove" }, | |
157 { "index", 100 } | |
158 }); | |
159 ctl_->recv([&] (auto code, auto) { | |
160 result = code; | |
161 }); | |
162 | |
163 wait_for([&] { | |
164 return result; | |
165 }); | |
166 | |
167 BOOST_ASSERT(result == rule_error::invalid_index); | |
168 } | |
169 | |
170 BOOST_AUTO_TEST_CASE(invalid_index_3) | |
171 { | |
172 boost::system::error_code result; | |
173 | |
174 ctl_->send({ | |
175 { "command", "rule-remove" }, | |
176 { "index", "notaint" } | |
177 }); | |
178 ctl_->recv([&] (auto code, auto) { | |
179 result = code; | |
180 }); | |
181 | |
182 wait_for([&] { | |
183 return result; | |
184 }); | |
185 | |
186 BOOST_ASSERT(result == rule_error::invalid_index); | |
187 } | |
188 | |
189 BOOST_AUTO_TEST_SUITE_END() | |
190 | |
191 BOOST_AUTO_TEST_SUITE_END() | |
192 | |
193 } // !irccd |