comparison tests/src/server-topic-command/main.cpp @ 609:168c0e191eea

Irccd: add more error properties, closes #754 Add two new properties in error messages: - errorMessage: the string message as-is, - errorCategory: the error category (e.g. server, rule). Adapt tests to test against the category.
author David Demelier <markand@malikania.fr>
date Thu, 14 Dec 2017 21:45:32 +0100
parents 9d4da384f5d6
children 22b3cd6f991f
comparison
equal deleted inserted replaced
608:5ee406d8dbe8 609:168c0e191eea
65 BOOST_AUTO_TEST_SUITE(errors) 65 BOOST_AUTO_TEST_SUITE(errors)
66 66
67 BOOST_AUTO_TEST_CASE(invalid_identifier_1) 67 BOOST_AUTO_TEST_CASE(invalid_identifier_1)
68 { 68 {
69 boost::system::error_code result; 69 boost::system::error_code result;
70 nlohmann::json message;
70 71
71 ctl_->send({ 72 ctl_->send({
72 { "command", "server-topic" }, 73 { "command", "server-topic" },
73 { "server", 123456 }, 74 { "server", 123456 },
74 { "channel", "#music" }, 75 { "channel", "#music" },
75 { "topic", "plop" } 76 { "topic", "plop" }
76 }); 77 });
77 ctl_->recv([&] (auto code, auto) { 78 ctl_->recv([&] (auto rresult, auto rmessage) {
78 result = code; 79 result = rresult;
80 message = rmessage;
79 }); 81 });
80 82
81 wait_for([&] { 83 wait_for([&] {
82 return result; 84 return result;
83 }); 85 });
84 86
85 BOOST_ASSERT(result == server_error::invalid_identifier); 87 BOOST_ASSERT(result == server_error::invalid_identifier);
88 BOOST_ASSERT(message["error"].template get<int>() == server_error::invalid_identifier);
89 BOOST_ASSERT(message["errorCategory"].template get<std::string>() == "server");
86 } 90 }
87 91
88 BOOST_AUTO_TEST_CASE(invalid_identifier_2) 92 BOOST_AUTO_TEST_CASE(invalid_identifier_2)
89 { 93 {
90 boost::system::error_code result; 94 boost::system::error_code result;
95 nlohmann::json message;
91 96
92 ctl_->send({ 97 ctl_->send({
93 { "command", "server-topic" }, 98 { "command", "server-topic" },
94 { "server", "" }, 99 { "server", "" },
95 { "channel", "#music" }, 100 { "channel", "#music" },
96 { "topic", "plop" } 101 { "topic", "plop" }
97 }); 102 });
98 ctl_->recv([&] (auto code, auto) { 103 ctl_->recv([&] (auto rresult, auto rmessage) {
99 result = code; 104 result = rresult;
105 message = rmessage;
100 }); 106 });
101 107
102 wait_for([&] { 108 wait_for([&] {
103 return result; 109 return result;
104 }); 110 });
105 111
106 BOOST_ASSERT(result == server_error::invalid_identifier); 112 BOOST_ASSERT(result == server_error::invalid_identifier);
113 BOOST_ASSERT(message["error"].template get<int>() == server_error::invalid_identifier);
114 BOOST_ASSERT(message["errorCategory"].template get<std::string>() == "server");
107 } 115 }
108 116
109 BOOST_AUTO_TEST_CASE(invalid_channel_1) 117 BOOST_AUTO_TEST_CASE(invalid_channel_1)
110 { 118 {
111 boost::system::error_code result; 119 boost::system::error_code result;
120 nlohmann::json message;
112 121
113 ctl_->send({ 122 ctl_->send({
114 { "command", "server-topic" }, 123 { "command", "server-topic" },
115 { "server", "test" }, 124 { "server", "test" },
116 { "channel", "" }, 125 { "channel", "" },
117 { "topic", "plop" } 126 { "topic", "plop" }
118 }); 127 });
119 ctl_->recv([&] (auto code, auto) { 128 ctl_->recv([&] (auto rresult, auto rmessage) {
120 result = code; 129 result = rresult;
130 message = rmessage;
121 }); 131 });
122 132
123 wait_for([&] { 133 wait_for([&] {
124 return result; 134 return result;
125 }); 135 });
126 136
127 BOOST_ASSERT(result == server_error::invalid_channel); 137 BOOST_ASSERT(result == server_error::invalid_channel);
138 BOOST_ASSERT(message["error"].template get<int>() == server_error::invalid_channel);
139 BOOST_ASSERT(message["errorCategory"].template get<std::string>() == "server");
128 } 140 }
129 141
130 BOOST_AUTO_TEST_CASE(invalid_channel_2) 142 BOOST_AUTO_TEST_CASE(invalid_channel_2)
131 { 143 {
132 boost::system::error_code result; 144 boost::system::error_code result;
145 nlohmann::json message;
133 146
134 ctl_->send({ 147 ctl_->send({
135 { "command", "server-topic" }, 148 { "command", "server-topic" },
136 { "server", "test" }, 149 { "server", "test" },
137 { "channel", 123456 }, 150 { "channel", 123456 },
138 { "topic", "plop" } 151 { "topic", "plop" }
139 }); 152 });
140 ctl_->recv([&] (auto code, auto) { 153 ctl_->recv([&] (auto rresult, auto rmessage) {
141 result = code; 154 result = rresult;
155 message = rmessage;
142 }); 156 });
143 157
144 wait_for([&] { 158 wait_for([&] {
145 return result; 159 return result;
146 }); 160 });
147 161
148 BOOST_ASSERT(result == server_error::invalid_channel); 162 BOOST_ASSERT(result == server_error::invalid_channel);
163 BOOST_ASSERT(message["error"].template get<int>() == server_error::invalid_channel);
164 BOOST_ASSERT(message["errorCategory"].template get<std::string>() == "server");
149 } 165 }
150 166
151 BOOST_AUTO_TEST_CASE(not_found) 167 BOOST_AUTO_TEST_CASE(not_found)
152 { 168 {
153 boost::system::error_code result; 169 boost::system::error_code result;
170 nlohmann::json message;
154 171
155 ctl_->send({ 172 ctl_->send({
156 { "command", "server-topic" }, 173 { "command", "server-topic" },
157 { "server", "unknown" }, 174 { "server", "unknown" },
158 { "channel", "#music" }, 175 { "channel", "#music" },
159 { "topic", "plop" } 176 { "topic", "plop" }
160 }); 177 });
161 ctl_->recv([&] (auto code, auto) { 178 ctl_->recv([&] (auto rresult, auto rmessage) {
162 result = code; 179 result = rresult;
180 message = rmessage;
163 }); 181 });
164 182
165 wait_for([&] { 183 wait_for([&] {
166 return result; 184 return result;
167 }); 185 });
168 186
169 BOOST_ASSERT(result == server_error::not_found); 187 BOOST_ASSERT(result == server_error::not_found);
188 BOOST_ASSERT(message["error"].template get<int>() == server_error::not_found);
189 BOOST_ASSERT(message["errorCategory"].template get<std::string>() == "server");
170 } 190 }
171 191
172 BOOST_AUTO_TEST_SUITE_END() 192 BOOST_AUTO_TEST_SUITE_END()
173 193
174 BOOST_AUTO_TEST_SUITE_END() 194 BOOST_AUTO_TEST_SUITE_END()