Mercurial > irccd
comparison tests/src/libirccd/command-plugin-config/main.cpp @ 651:1081e45b8628
Tests: use command_test::request helper, closes #784 @1h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 27 Mar 2018 20:12:02 +0200 |
parents | 23fd8bad4006 |
children | 95ac3ace1610 |
comparison
equal
deleted
inserted
replaced
650:27896e9bcd9e | 651:1081e45b8628 |
---|---|
79 | 79 |
80 plugin->set_config({ | 80 plugin->set_config({ |
81 { "x1", "10" }, | 81 { "x1", "10" }, |
82 { "x2", "20" } | 82 { "x2", "20" } |
83 }); | 83 }); |
84 daemon_->plugins().add(std::move(plugin)); | |
84 | 85 |
85 daemon_->plugins().add(std::move(plugin)); | 86 auto result = request({ |
86 ctl_->send({ | 87 { "command", "plugin-config" }, |
87 { "command", "plugin-config" }, | 88 { "plugin", "test" }, |
88 { "plugin", "test" }, | 89 { "variable", "x1" } |
89 { "variable", "x1" } | |
90 }); | |
91 ctl_->recv([&] (auto, auto message) { | |
92 json = std::move(message); | |
93 }); | 90 }); |
94 | 91 |
95 wait_for([&] { | 92 BOOST_TEST(result.first["variables"]["x1"].get<std::string>() == "10"); |
96 return json.is_object(); | 93 BOOST_TEST(result.first["variables"]["x2"].is_null()); |
97 }); | |
98 | |
99 BOOST_TEST(json.is_object()); | |
100 BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); | |
101 BOOST_TEST(json["variables"]["x2"].is_null()); | |
102 } | 94 } |
103 | 95 |
104 BOOST_AUTO_TEST_CASE(getall) | 96 BOOST_AUTO_TEST_CASE(getall) |
105 { | 97 { |
106 auto plugin = std::make_unique<custom_plugin>("test"); | 98 auto plugin = std::make_unique<custom_plugin>("test"); |
108 | 100 |
109 plugin->set_config({ | 101 plugin->set_config({ |
110 { "x1", "10" }, | 102 { "x1", "10" }, |
111 { "x2", "20" } | 103 { "x2", "20" } |
112 }); | 104 }); |
105 daemon_->plugins().add(std::move(plugin)); | |
113 | 106 |
114 daemon_->plugins().add(std::move(plugin)); | 107 auto result = request({ |
115 ctl_->send({ | |
116 { "command", "plugin-config" }, | 108 { "command", "plugin-config" }, |
117 { "plugin", "test" } | 109 { "plugin", "test" } |
118 }); | 110 }); |
119 ctl_->recv([&] (auto, auto message) { | |
120 json = std::move(message); | |
121 }); | |
122 | 111 |
123 wait_for([&] { | 112 BOOST_TEST(result.first["variables"]["x1"].get<std::string>() == "10"); |
124 return json.is_object(); | 113 BOOST_TEST(result.first["variables"]["x2"].get<std::string>() == "20"); |
125 }); | |
126 | |
127 BOOST_TEST(json.is_object()); | |
128 BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); | |
129 BOOST_TEST(json["variables"]["x2"].get<std::string>() == "20"); | |
130 } | 114 } |
131 | 115 |
132 BOOST_AUTO_TEST_SUITE(errors) | 116 BOOST_AUTO_TEST_SUITE(errors) |
133 | 117 |
134 BOOST_AUTO_TEST_CASE(invalid_identifier) | 118 BOOST_AUTO_TEST_CASE(invalid_identifier) |
135 { | 119 { |
136 boost::system::error_code result; | 120 const auto result = request({ |
137 nlohmann::json message; | |
138 | |
139 ctl_->send({ | |
140 { "command", "plugin-config" } | 121 { "command", "plugin-config" } |
141 }); | 122 }); |
142 ctl_->recv([&] (auto rresult, auto rmessage) { | |
143 result = rresult; | |
144 message = rmessage; | |
145 }); | |
146 | 123 |
147 wait_for([&] { | 124 BOOST_TEST(result.second == plugin_error::invalid_identifier); |
148 return result; | 125 BOOST_TEST(result.first["error"].template get<int>() == plugin_error::invalid_identifier); |
149 }); | 126 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "plugin"); |
150 | |
151 BOOST_TEST(result == plugin_error::invalid_identifier); | |
152 BOOST_TEST(message["error"].template get<int>() == plugin_error::invalid_identifier); | |
153 BOOST_TEST(message["errorCategory"].template get<std::string>() == "plugin"); | |
154 } | 127 } |
155 | 128 |
156 BOOST_AUTO_TEST_CASE(not_found) | 129 BOOST_AUTO_TEST_CASE(not_found) |
157 { | 130 { |
158 boost::system::error_code result; | 131 const auto result = request({ |
159 nlohmann::json message; | |
160 | |
161 ctl_->send({ | |
162 { "command", "plugin-config" }, | 132 { "command", "plugin-config" }, |
163 { "plugin", "unknown" } | 133 { "plugin", "unknown" } |
164 }); | 134 }); |
165 ctl_->recv([&] (auto rresult, auto rmessage) { | |
166 result = rresult; | |
167 message = rmessage; | |
168 }); | |
169 | 135 |
170 wait_for([&] { | 136 BOOST_TEST(result.second == plugin_error::not_found); |
171 return result; | 137 BOOST_TEST(result.first["error"].template get<int>() == plugin_error::not_found); |
172 }); | 138 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "plugin"); |
173 | |
174 BOOST_TEST(result == plugin_error::not_found); | |
175 BOOST_TEST(message["error"].template get<int>() == plugin_error::not_found); | |
176 BOOST_TEST(message["errorCategory"].template get<std::string>() == "plugin"); | |
177 } | 139 } |
178 | 140 |
179 BOOST_AUTO_TEST_SUITE_END() | 141 BOOST_AUTO_TEST_SUITE_END() |
180 | 142 |
181 BOOST_AUTO_TEST_SUITE_END() | 143 BOOST_AUTO_TEST_SUITE_END() |