Mercurial > irccd
comparison tests/src/libirccd/command-server-connect/main.cpp @ 737:190b16cfa848
Tests: improve command tests readability
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 24 Jul 2018 23:01:00 +0200 |
parents | 64839725f346 |
children | 8876412ba633 |
comparison
equal
deleted
inserted
replaced
736:49b7c7660a00 | 737:190b16cfa848 |
---|---|
31 | 31 |
32 BOOST_FIXTURE_TEST_SUITE(server_connect_test_suite, command_test<server_connect_command>) | 32 BOOST_FIXTURE_TEST_SUITE(server_connect_test_suite, command_test<server_connect_command>) |
33 | 33 |
34 BOOST_AUTO_TEST_CASE(minimal) | 34 BOOST_AUTO_TEST_CASE(minimal) |
35 { | 35 { |
36 const auto result = request({ | 36 const auto [json, code] = request({ |
37 { "command", "server-connect" }, | 37 { "command", "server-connect" }, |
38 { "name", "local" }, | 38 { "name", "local" }, |
39 { "host", "irc.example.org" } | 39 { "host", "irc.example.org" } |
40 }); | 40 }); |
41 | 41 |
42 const auto s = daemon_->servers().get("local"); | 42 const auto s = daemon_->servers().get("local"); |
43 | 43 |
44 BOOST_TEST(!code); | |
44 BOOST_TEST(s); | 45 BOOST_TEST(s); |
45 BOOST_TEST(s->get_id() == "local"); | 46 BOOST_TEST(s->get_id() == "local"); |
46 BOOST_TEST(s->get_host() == "irc.example.org"); | 47 BOOST_TEST(s->get_host() == "irc.example.org"); |
47 BOOST_TEST(s->get_port() == 6667U); | 48 BOOST_TEST(s->get_port() == 6667U); |
48 } | 49 } |
49 | 50 |
50 #if defined(IRCCD_HAVE_SSL) | 51 #if defined(IRCCD_HAVE_SSL) |
51 | 52 |
52 BOOST_AUTO_TEST_CASE(full) | 53 BOOST_AUTO_TEST_CASE(full) |
53 { | 54 { |
54 const auto result = request({ | 55 const auto [json, code] = request({ |
55 { "command", "server-connect" }, | 56 { "command", "server-connect" }, |
56 { "name", "local2" }, | 57 { "name", "local2" }, |
57 { "host", "irc.example2.org" }, | 58 { "host", "irc.example2.org" }, |
58 { "password", "nonono" }, | 59 { "password", "nonono" }, |
59 { "nickname", "francis" }, | 60 { "nickname", "francis" }, |
68 { "joinInvite", true } | 69 { "joinInvite", true } |
69 }); | 70 }); |
70 | 71 |
71 const auto s = daemon_->servers().get("local2"); | 72 const auto s = daemon_->servers().get("local2"); |
72 | 73 |
74 BOOST_TEST(!code); | |
73 BOOST_TEST(s); | 75 BOOST_TEST(s); |
74 BOOST_TEST(s->get_id() == "local2"); | 76 BOOST_TEST(s->get_id() == "local2"); |
75 BOOST_TEST(s->get_host() == "irc.example2.org"); | 77 BOOST_TEST(s->get_host() == "irc.example2.org"); |
76 BOOST_TEST(s->get_port() == 18000U); | 78 BOOST_TEST(s->get_port() == 18000U); |
77 BOOST_TEST(s->get_password() == "nonono"); | 79 BOOST_TEST(s->get_password() == "nonono"); |
92 | 94 |
93 BOOST_AUTO_TEST_CASE(already_exists) | 95 BOOST_AUTO_TEST_CASE(already_exists) |
94 { | 96 { |
95 daemon_->servers().add(std::make_unique<mock_server>(service_, "local")); | 97 daemon_->servers().add(std::make_unique<mock_server>(service_, "local")); |
96 | 98 |
97 const auto result = request({ | 99 const auto [json, code] = request({ |
98 { "command", "server-connect" }, | 100 { "command", "server-connect" }, |
99 { "name", "local" }, | 101 { "name", "local" }, |
100 { "host", "127.0.0.1" } | 102 { "host", "127.0.0.1" } |
101 }); | 103 }); |
102 | 104 |
103 BOOST_TEST(result.second == server_error::already_exists); | 105 BOOST_TEST(code == server_error::already_exists); |
104 BOOST_TEST(result.first["error"].template get<int>() == server_error::already_exists); | 106 BOOST_TEST(json["error"].get<int>() == server_error::already_exists); |
105 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 107 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
106 } | 108 } |
107 | 109 |
108 BOOST_AUTO_TEST_CASE(invalid_hostname_1) | 110 BOOST_AUTO_TEST_CASE(invalid_hostname_1) |
109 { | 111 { |
110 const auto result = request({ | 112 const auto [json, code] = request({ |
111 { "command", "server-connect" }, | 113 { "command", "server-connect" }, |
112 { "name", "new" }, | 114 { "name", "new" }, |
113 }); | 115 }); |
114 | 116 |
115 BOOST_TEST(result.second == server_error::invalid_hostname); | 117 BOOST_TEST(code == server_error::invalid_hostname); |
116 BOOST_TEST(result.first["error"].template get<int>() == server_error::invalid_hostname); | 118 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); |
117 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 119 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
118 } | 120 } |
119 | 121 |
120 BOOST_AUTO_TEST_CASE(invalid_hostname_2) | 122 BOOST_AUTO_TEST_CASE(invalid_hostname_2) |
121 { | 123 { |
122 const auto result = request({ | 124 const auto [json, code] = request({ |
123 { "command", "server-connect" }, | 125 { "command", "server-connect" }, |
124 { "name", "new" }, | 126 { "name", "new" }, |
125 { "host", 123456 } | 127 { "host", 123456 } |
126 }); | 128 }); |
127 | 129 |
128 BOOST_TEST(result.second == server_error::invalid_hostname); | 130 BOOST_TEST(code == server_error::invalid_hostname); |
129 BOOST_TEST(result.first["error"].template get<int>() == server_error::invalid_hostname); | 131 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); |
130 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 132 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
131 } | 133 } |
132 | 134 |
133 BOOST_AUTO_TEST_CASE(invalid_identifier_1) | 135 BOOST_AUTO_TEST_CASE(invalid_identifier_1) |
134 { | 136 { |
135 const auto result = request({ | 137 const auto [json, code] = request({ |
136 { "command", "server-connect" }, | 138 { "command", "server-connect" }, |
137 { "name", "" }, | 139 { "name", "" }, |
138 { "host", "127.0.0.1" } | 140 { "host", "127.0.0.1" } |
139 }); | 141 }); |
140 | 142 |
141 BOOST_TEST(result.second == server_error::invalid_identifier); | 143 BOOST_TEST(code == server_error::invalid_identifier); |
142 BOOST_TEST(result.first["error"].template get<int>() == server_error::invalid_identifier); | 144 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); |
143 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 145 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
144 } | 146 } |
145 | 147 |
146 BOOST_AUTO_TEST_CASE(invalid_identifier_2) | 148 BOOST_AUTO_TEST_CASE(invalid_identifier_2) |
147 { | 149 { |
148 const auto result = request({ | 150 const auto [json, code] = request({ |
149 { "command", "server-connect" }, | 151 { "command", "server-connect" }, |
150 { "name", 123456 }, | 152 { "name", 123456 }, |
151 { "host", "127.0.0.1" } | 153 { "host", "127.0.0.1" } |
152 }); | 154 }); |
153 | 155 |
154 BOOST_TEST(result.second == server_error::invalid_identifier); | 156 BOOST_TEST(code == server_error::invalid_identifier); |
155 BOOST_TEST(result.first["error"].template get<int>() == server_error::invalid_identifier); | 157 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); |
156 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 158 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
157 } | 159 } |
158 | 160 |
159 BOOST_AUTO_TEST_CASE(invalid_port_1) | 161 BOOST_AUTO_TEST_CASE(invalid_port_1) |
160 { | 162 { |
161 const auto result = request({ | 163 const auto [json, code] = request({ |
162 { "command", "server-connect" }, | 164 { "command", "server-connect" }, |
163 { "name", "new" }, | 165 { "name", "new" }, |
164 { "host", "127.0.0.1" }, | 166 { "host", "127.0.0.1" }, |
165 { "port", "notaint" } | 167 { "port", "notaint" } |
166 }); | 168 }); |
167 | 169 |
168 BOOST_TEST(result.second == server_error::invalid_port); | 170 BOOST_TEST(code == server_error::invalid_port); |
169 BOOST_TEST(result.first["error"].template get<int>() == server_error::invalid_port); | 171 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
170 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 172 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
171 } | 173 } |
172 | 174 |
173 BOOST_AUTO_TEST_CASE(invalid_port_2) | 175 BOOST_AUTO_TEST_CASE(invalid_port_2) |
174 { | 176 { |
175 const auto result = request({ | 177 const auto [json, code] = request({ |
176 { "command", "server-connect" }, | 178 { "command", "server-connect" }, |
177 { "name", "new" }, | 179 { "name", "new" }, |
178 { "host", "127.0.0.1" }, | 180 { "host", "127.0.0.1" }, |
179 { "port", -123 } | 181 { "port", -123 } |
180 }); | 182 }); |
181 | 183 |
182 BOOST_TEST(result.second == server_error::invalid_port); | 184 BOOST_TEST(code == server_error::invalid_port); |
183 BOOST_TEST(result.first["error"].template get<int>() == server_error::invalid_port); | 185 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
184 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 186 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
185 } | 187 } |
186 | 188 |
187 BOOST_AUTO_TEST_CASE(invalid_port_3) | 189 BOOST_AUTO_TEST_CASE(invalid_port_3) |
188 { | 190 { |
189 const auto result = request({ | 191 const auto [json, code] = request({ |
190 { "command", "server-connect" }, | 192 { "command", "server-connect" }, |
191 { "name", "new" }, | 193 { "name", "new" }, |
192 { "host", "127.0.0.1" }, | 194 { "host", "127.0.0.1" }, |
193 { "port", 1000000 } | 195 { "port", 1000000 } |
194 }); | 196 }); |
195 | 197 |
196 BOOST_TEST(result.second == server_error::invalid_port); | 198 BOOST_TEST(code == server_error::invalid_port); |
197 BOOST_TEST(result.first["error"].template get<int>() == server_error::invalid_port); | 199 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
198 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 200 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
199 } | 201 } |
200 | 202 |
201 #if !defined(IRCCD_HAVE_SSL) | 203 #if !defined(IRCCD_HAVE_SSL) |
202 | 204 |
203 BOOST_AUTO_TEST_CASE(ssl_disabled) | 205 BOOST_AUTO_TEST_CASE(ssl_disabled) |
204 { | 206 { |
205 const auto result = request({ | 207 const auto [json, code] = request({ |
206 { "command", "server-connect" }, | 208 { "command", "server-connect" }, |
207 { "name", "new" }, | 209 { "name", "new" }, |
208 { "host", "127.0.0.1" }, | 210 { "host", "127.0.0.1" }, |
209 { "ssl", true } | 211 { "ssl", true } |
210 }); | 212 }); |
211 | 213 |
212 BOOST_TEST(result.second == server_error::ssl_disabled); | 214 BOOST_TEST(code == server_error::ssl_disabled); |
213 BOOST_TEST(result.first["error"].template get<int>() == server_error::ssl_disabled); | 215 BOOST_TEST(json["error"].get<int>() == server_error::ssl_disabled); |
214 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "server"); | 216 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
215 } | 217 } |
216 | 218 |
217 #endif | 219 #endif |
218 | 220 |
219 BOOST_AUTO_TEST_SUITE_END() | 221 BOOST_AUTO_TEST_SUITE_END() |