comparison tests/rule-info-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-rule-info/main.cpp@17207a09a6b4
children
comparison
equal deleted inserted replaced
578:a8b892177909 579:84ea13c850f4
1 /*
2 * main.cpp -- test rule-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 "rule-info"
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_info_test : public command_test<rule_info_command> {
34 public:
35 rule_info_test()
36 {
37 daemon_->rules().add(rule(
38 { "s1", "s2" },
39 { "c1", "c2" },
40 { "o1", "o2" },
41 { "p1", "p2" },
42 { "onMessage", "onCommand" },
43 rule::action_type::drop
44 ));
45 daemon_->rules().add(rule(
46 { "s1", },
47 { "c1", },
48 { "o1", },
49 { "p1", },
50 { "onMessage", },
51 rule::action_type::accept
52 ));
53 }
54 };
55
56 } // !namespace
57
58 BOOST_FIXTURE_TEST_SUITE(rule_info_test_suite, rule_info_test)
59
60 BOOST_AUTO_TEST_CASE(basic)
61 {
62 nlohmann::json result;
63
64 ctl_->send({
65 { "command", "rule-info" },
66 { "index", 0 }
67 });
68 ctl_->recv([&] (auto, auto msg) {
69 result = msg;
70 });
71
72 wait_for([&] () {
73 return result.is_object();
74 });
75
76 BOOST_TEST(result.is_object());
77
78 auto servers = result["servers"];
79 auto channels = result["channels"];
80 auto plugins = result["plugins"];
81 auto events = result["events"];
82
83 BOOST_TEST(json_util::contains(servers, "s1"));
84 BOOST_TEST(json_util::contains(servers, "s2"));
85 BOOST_TEST(json_util::contains(channels, "c1"));
86 BOOST_TEST(json_util::contains(channels, "c2"));
87 BOOST_TEST(json_util::contains(plugins, "p1"));
88 BOOST_TEST(json_util::contains(plugins, "p2"));
89 BOOST_TEST(json_util::contains(events, "onMessage"));
90 BOOST_TEST(json_util::contains(events, "onCommand"));
91 BOOST_TEST(result["action"].get<std::string>() == "drop");
92 }
93
94 BOOST_AUTO_TEST_SUITE(errors)
95
96 BOOST_AUTO_TEST_CASE(invalid_index_1)
97 {
98 boost::system::error_code result;
99
100 ctl_->send({
101 { "command", "rule-info" },
102 { "index", -100 }
103 });
104 ctl_->recv([&] (auto code, auto) {
105 result = code;
106 });
107
108 wait_for([&] {
109 return result;
110 });
111
112 BOOST_ASSERT(result == rule_error::invalid_index);
113 }
114
115 BOOST_AUTO_TEST_CASE(invalid_index_2)
116 {
117 boost::system::error_code result;
118
119 ctl_->send({
120 { "command", "rule-info" },
121 { "index", 100 }
122 });
123 ctl_->recv([&] (auto code, auto) {
124 result = code;
125 });
126
127 wait_for([&] {
128 return result;
129 });
130
131 BOOST_ASSERT(result == rule_error::invalid_index);
132 }
133
134 BOOST_AUTO_TEST_CASE(invalid_index_3)
135 {
136 boost::system::error_code result;
137
138 ctl_->send({
139 { "command", "rule-info" },
140 { "index", "notaint" }
141 });
142 ctl_->recv([&] (auto code, auto) {
143 result = code;
144 });
145
146 wait_for([&] {
147 return result;
148 });
149
150 BOOST_ASSERT(result == rule_error::invalid_index);
151 }
152
153 BOOST_AUTO_TEST_SUITE_END()
154
155 BOOST_AUTO_TEST_SUITE_END()
156
157 } // !irccd