Mercurial > irccd
comparison tests/src/libirccd/command-plugin-config/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 | 9d13aabfd63a |
children | 199f36d4edc8 |
comparison
equal
deleted
inserted
replaced
736:49b7c7660a00 | 737:190b16cfa848 |
---|---|
56 BOOST_FIXTURE_TEST_SUITE(plugin_config_test_suite, command_test<plugin_config_command>) | 56 BOOST_FIXTURE_TEST_SUITE(plugin_config_test_suite, command_test<plugin_config_command>) |
57 | 57 |
58 BOOST_AUTO_TEST_CASE(set) | 58 BOOST_AUTO_TEST_CASE(set) |
59 { | 59 { |
60 daemon_->plugins().add(std::make_unique<custom_plugin>()); | 60 daemon_->plugins().add(std::make_unique<custom_plugin>()); |
61 ctl_->write({ | 61 |
62 const auto [json, code] = request({ | |
62 { "command", "plugin-config" }, | 63 { "command", "plugin-config" }, |
63 { "plugin", "test" }, | 64 { "plugin", "test" }, |
64 { "variable", "verbosy" }, | 65 { "variable", "verbosy" }, |
65 { "value", "falsy" } | 66 { "value", "falsy" } |
66 }); | 67 }); |
67 | 68 |
68 wait_for([&] { | 69 const auto config = daemon_->plugins().require("test")->get_options(); |
69 return !daemon_->plugins().require("test")->get_options().empty(); | |
70 }); | |
71 | 70 |
72 auto config = daemon_->plugins().require("test")->get_options(); | 71 BOOST_TEST(!code); |
73 | |
74 BOOST_TEST(!config.empty()); | 72 BOOST_TEST(!config.empty()); |
75 BOOST_TEST(config["verbosy"] == "falsy"); | 73 BOOST_TEST(config.at("verbosy") == "falsy"); |
76 } | 74 } |
77 | 75 |
78 BOOST_AUTO_TEST_CASE(get) | 76 BOOST_AUTO_TEST_CASE(get) |
79 { | 77 { |
80 auto plugin = std::make_unique<custom_plugin>(); | 78 auto plugin = std::make_unique<custom_plugin>(); |
81 auto json = nlohmann::json(); | |
82 | 79 |
83 plugin->set_options({ | 80 plugin->set_options({ |
84 { "x1", "10" }, | 81 { "x1", "10" }, |
85 { "x2", "20" } | 82 { "x2", "20" } |
86 }); | 83 }); |
87 daemon_->plugins().add(std::move(plugin)); | 84 daemon_->plugins().add(std::move(plugin)); |
88 | 85 |
89 auto result = request({ | 86 const auto [json, code] = request({ |
90 { "command", "plugin-config" }, | 87 { "command", "plugin-config" }, |
91 { "plugin", "test" }, | 88 { "plugin", "test" }, |
92 { "variable", "x1" } | 89 { "variable", "x1" } |
93 }); | 90 }); |
94 | 91 |
95 BOOST_TEST(result.first["variables"]["x1"].get<std::string>() == "10"); | 92 BOOST_TEST(!code); |
96 BOOST_TEST(result.first["variables"]["x2"].is_null()); | 93 BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); |
94 BOOST_TEST(json["variables"].count("x2") == 0U); | |
97 } | 95 } |
98 | 96 |
99 BOOST_AUTO_TEST_CASE(getall) | 97 BOOST_AUTO_TEST_CASE(getall) |
100 { | 98 { |
101 auto plugin = std::make_unique<custom_plugin>(); | 99 auto plugin = std::make_unique<custom_plugin>(); |
102 auto json = nlohmann::json(); | |
103 | 100 |
104 plugin->set_options({ | 101 plugin->set_options({ |
105 { "x1", "10" }, | 102 { "x1", "10" }, |
106 { "x2", "20" } | 103 { "x2", "20" } |
107 }); | 104 }); |
108 daemon_->plugins().add(std::move(plugin)); | 105 daemon_->plugins().add(std::move(plugin)); |
109 | 106 |
110 auto result = request({ | 107 const auto [json, code] = request({ |
111 { "command", "plugin-config" }, | 108 { "command", "plugin-config" }, |
112 { "plugin", "test" } | 109 { "plugin", "test" } |
113 }); | 110 }); |
114 | 111 |
115 BOOST_TEST(result.first["variables"]["x1"].get<std::string>() == "10"); | 112 BOOST_TEST(!code); |
116 BOOST_TEST(result.first["variables"]["x2"].get<std::string>() == "20"); | 113 BOOST_TEST(json["variables"]["x1"].get<std::string>() == "10"); |
114 BOOST_TEST(json["variables"]["x2"].get<std::string>() == "20"); | |
117 } | 115 } |
118 | 116 |
119 BOOST_AUTO_TEST_SUITE(errors) | 117 BOOST_AUTO_TEST_SUITE(errors) |
120 | 118 |
121 BOOST_AUTO_TEST_CASE(invalid_identifier) | 119 BOOST_AUTO_TEST_CASE(invalid_identifier) |
122 { | 120 { |
123 const auto result = request({ | 121 const auto [json, code] = request({ |
124 { "command", "plugin-config" } | 122 { "command", "plugin-config" } |
125 }); | 123 }); |
126 | 124 |
127 BOOST_TEST(result.second == plugin_error::invalid_identifier); | 125 BOOST_TEST(code == plugin_error::invalid_identifier); |
128 BOOST_TEST(result.first["error"].template get<int>() == plugin_error::invalid_identifier); | 126 BOOST_TEST(json["error"].get<int>() == plugin_error::invalid_identifier); |
129 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "plugin"); | 127 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); |
130 } | 128 } |
131 | 129 |
132 BOOST_AUTO_TEST_CASE(not_found) | 130 BOOST_AUTO_TEST_CASE(not_found) |
133 { | 131 { |
134 const auto result = request({ | 132 const auto [json, code] = request({ |
135 { "command", "plugin-config" }, | 133 { "command", "plugin-config" }, |
136 { "plugin", "unknown" } | 134 { "plugin", "unknown" } |
137 }); | 135 }); |
138 | 136 |
139 BOOST_TEST(result.second == plugin_error::not_found); | 137 BOOST_TEST(code == plugin_error::not_found); |
140 BOOST_TEST(result.first["error"].template get<int>() == plugin_error::not_found); | 138 BOOST_TEST(json["error"].get<int>() == plugin_error::not_found); |
141 BOOST_TEST(result.first["errorCategory"].template get<std::string>() == "plugin"); | 139 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); |
142 } | 140 } |
143 | 141 |
144 BOOST_AUTO_TEST_SUITE_END() | 142 BOOST_AUTO_TEST_SUITE_END() |
145 | 143 |
146 BOOST_AUTO_TEST_SUITE_END() | 144 BOOST_AUTO_TEST_SUITE_END() |