Mercurial > irccd
comparison tests/src/libirccd/command-server-connect/main.cpp @ 785:7145a3df4cb7
misc: rename host to hostname, closes #941 @2h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 07 Nov 2018 12:55:00 +0100 |
parents | 8c44bbcbbab9 |
children | 3c090c1ff4f0 |
comparison
equal
deleted
inserted
replaced
783:d0bd19183743 | 785:7145a3df4cb7 |
---|---|
32 BOOST_AUTO_TEST_CASE(minimal) | 32 BOOST_AUTO_TEST_CASE(minimal) |
33 { | 33 { |
34 const auto [json, code] = request({ | 34 const auto [json, code] = request({ |
35 { "command", "server-connect" }, | 35 { "command", "server-connect" }, |
36 { "name", "local" }, | 36 { "name", "local" }, |
37 { "host", "irc.example.org" } | 37 { "hostname", "irc.example.org" } |
38 }); | 38 }); |
39 | 39 |
40 const auto s = irccd_.servers().get("local"); | 40 const auto s = irccd_.servers().get("local"); |
41 | 41 |
42 BOOST_TEST(!code); | 42 BOOST_TEST(!code); |
43 BOOST_TEST(s); | 43 BOOST_TEST(s); |
44 BOOST_TEST(s->get_id() == "local"); | 44 BOOST_TEST(s->get_id() == "local"); |
45 BOOST_TEST(s->get_host() == "irc.example.org"); | 45 BOOST_TEST(s->get_hostname() == "irc.example.org"); |
46 BOOST_TEST(s->get_port() == 6667U); | 46 BOOST_TEST(s->get_port() == 6667U); |
47 } | 47 } |
48 | 48 |
49 #if defined(IRCCD_HAVE_SSL) | 49 #if defined(IRCCD_HAVE_SSL) |
50 | 50 |
51 BOOST_AUTO_TEST_CASE(full) | 51 BOOST_AUTO_TEST_CASE(full) |
52 { | 52 { |
53 const auto [json, code] = request({ | 53 const auto [json, code] = request({ |
54 { "command", "server-connect" }, | 54 { "command", "server-connect" }, |
55 { "name", "local2" }, | 55 { "name", "local2" }, |
56 { "host", "irc.example2.org" }, | 56 { "hostname", "irc.example2.org" }, |
57 { "password", "nonono" }, | 57 { "password", "nonono" }, |
58 { "nickname", "francis" }, | 58 { "nickname", "francis" }, |
59 { "realname", "the_francis" }, | 59 { "realname", "the_francis" }, |
60 { "username", "frc" }, | 60 { "username", "frc" }, |
61 { "ctcpVersion", "ultra bot" }, | 61 { "ctcpVersion", "ultra bot" }, |
70 const auto s = irccd_.servers().get("local2"); | 70 const auto s = irccd_.servers().get("local2"); |
71 | 71 |
72 BOOST_TEST(!code); | 72 BOOST_TEST(!code); |
73 BOOST_TEST(s); | 73 BOOST_TEST(s); |
74 BOOST_TEST(s->get_id() == "local2"); | 74 BOOST_TEST(s->get_id() == "local2"); |
75 BOOST_TEST(s->get_host() == "irc.example2.org"); | 75 BOOST_TEST(s->get_hostname() == "irc.example2.org"); |
76 BOOST_TEST(s->get_port() == 18000U); | 76 BOOST_TEST(s->get_port() == 18000U); |
77 BOOST_TEST(s->get_password() == "nonono"); | 77 BOOST_TEST(s->get_password() == "nonono"); |
78 BOOST_TEST(s->get_nickname() == "francis"); | 78 BOOST_TEST(s->get_nickname() == "francis"); |
79 BOOST_TEST(s->get_realname() == "the_francis"); | 79 BOOST_TEST(s->get_realname() == "the_francis"); |
80 BOOST_TEST(s->get_username() == "frc"); | 80 BOOST_TEST(s->get_username() == "frc"); |
95 irccd_.servers().add(std::make_unique<mock_server>(ctx_, "local")); | 95 irccd_.servers().add(std::make_unique<mock_server>(ctx_, "local")); |
96 | 96 |
97 const auto [json, code] = request({ | 97 const auto [json, code] = request({ |
98 { "command", "server-connect" }, | 98 { "command", "server-connect" }, |
99 { "name", "local" }, | 99 { "name", "local" }, |
100 { "host", "127.0.0.1" } | 100 { "hostname", "127.0.0.1" } |
101 }); | 101 }); |
102 | 102 |
103 BOOST_TEST(code == server_error::already_exists); | 103 BOOST_TEST(code == server_error::already_exists); |
104 BOOST_TEST(json["error"].get<int>() == server_error::already_exists); | 104 BOOST_TEST(json["error"].get<int>() == server_error::already_exists); |
105 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 105 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
120 BOOST_AUTO_TEST_CASE(invalid_hostname_2) | 120 BOOST_AUTO_TEST_CASE(invalid_hostname_2) |
121 { | 121 { |
122 const auto [json, code] = request({ | 122 const auto [json, code] = request({ |
123 { "command", "server-connect" }, | 123 { "command", "server-connect" }, |
124 { "name", "new" }, | 124 { "name", "new" }, |
125 { "host", 123456 } | 125 { "hostname", 123456 } |
126 }); | 126 }); |
127 | 127 |
128 BOOST_TEST(code == server_error::invalid_hostname); | 128 BOOST_TEST(code == server_error::invalid_hostname); |
129 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); | 129 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); |
130 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 130 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
133 BOOST_AUTO_TEST_CASE(invalid_identifier_1) | 133 BOOST_AUTO_TEST_CASE(invalid_identifier_1) |
134 { | 134 { |
135 const auto [json, code] = request({ | 135 const auto [json, code] = request({ |
136 { "command", "server-connect" }, | 136 { "command", "server-connect" }, |
137 { "name", "" }, | 137 { "name", "" }, |
138 { "host", "127.0.0.1" } | 138 { "hostname", "127.0.0.1" } |
139 }); | 139 }); |
140 | 140 |
141 BOOST_TEST(code == server_error::invalid_identifier); | 141 BOOST_TEST(code == server_error::invalid_identifier); |
142 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); | 142 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); |
143 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 143 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
146 BOOST_AUTO_TEST_CASE(invalid_identifier_2) | 146 BOOST_AUTO_TEST_CASE(invalid_identifier_2) |
147 { | 147 { |
148 const auto [json, code] = request({ | 148 const auto [json, code] = request({ |
149 { "command", "server-connect" }, | 149 { "command", "server-connect" }, |
150 { "name", 123456 }, | 150 { "name", 123456 }, |
151 { "host", "127.0.0.1" } | 151 { "hostname", "127.0.0.1" } |
152 }); | 152 }); |
153 | 153 |
154 BOOST_TEST(code == server_error::invalid_identifier); | 154 BOOST_TEST(code == server_error::invalid_identifier); |
155 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); | 155 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); |
156 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); | 156 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); |
159 BOOST_AUTO_TEST_CASE(invalid_port_1) | 159 BOOST_AUTO_TEST_CASE(invalid_port_1) |
160 { | 160 { |
161 const auto [json, code] = request({ | 161 const auto [json, code] = request({ |
162 { "command", "server-connect" }, | 162 { "command", "server-connect" }, |
163 { "name", "new" }, | 163 { "name", "new" }, |
164 { "host", "127.0.0.1" }, | 164 { "hostname", "127.0.0.1" }, |
165 { "port", "notaint" } | 165 { "port", "notaint" } |
166 }); | 166 }); |
167 | 167 |
168 BOOST_TEST(code == server_error::invalid_port); | 168 BOOST_TEST(code == server_error::invalid_port); |
169 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); | 169 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
173 BOOST_AUTO_TEST_CASE(invalid_port_2) | 173 BOOST_AUTO_TEST_CASE(invalid_port_2) |
174 { | 174 { |
175 const auto [json, code] = request({ | 175 const auto [json, code] = request({ |
176 { "command", "server-connect" }, | 176 { "command", "server-connect" }, |
177 { "name", "new" }, | 177 { "name", "new" }, |
178 { "host", "127.0.0.1" }, | 178 { "hostname", "127.0.0.1" }, |
179 { "port", -123 } | 179 { "port", -123 } |
180 }); | 180 }); |
181 | 181 |
182 BOOST_TEST(code == server_error::invalid_port); | 182 BOOST_TEST(code == server_error::invalid_port); |
183 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); | 183 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
187 BOOST_AUTO_TEST_CASE(invalid_port_3) | 187 BOOST_AUTO_TEST_CASE(invalid_port_3) |
188 { | 188 { |
189 const auto [json, code] = request({ | 189 const auto [json, code] = request({ |
190 { "command", "server-connect" }, | 190 { "command", "server-connect" }, |
191 { "name", "new" }, | 191 { "name", "new" }, |
192 { "host", "127.0.0.1" }, | 192 { "hostname", "127.0.0.1" }, |
193 { "port", 1000000 } | 193 { "port", 1000000 } |
194 }); | 194 }); |
195 | 195 |
196 BOOST_TEST(code == server_error::invalid_port); | 196 BOOST_TEST(code == server_error::invalid_port); |
197 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); | 197 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); |
203 BOOST_AUTO_TEST_CASE(ssl_disabled) | 203 BOOST_AUTO_TEST_CASE(ssl_disabled) |
204 { | 204 { |
205 const auto [json, code] = request({ | 205 const auto [json, code] = request({ |
206 { "command", "server-connect" }, | 206 { "command", "server-connect" }, |
207 { "name", "new" }, | 207 { "name", "new" }, |
208 { "host", "127.0.0.1" }, | 208 { "hostname", "127.0.0.1" }, |
209 { "ssl", true } | 209 { "ssl", true } |
210 }); | 210 }); |
211 | 211 |
212 BOOST_TEST(code == server_error::ssl_disabled); | 212 BOOST_TEST(code == server_error::ssl_disabled); |
213 BOOST_TEST(json["error"].get<int>() == server_error::ssl_disabled); | 213 BOOST_TEST(json["error"].get<int>() == server_error::ssl_disabled); |