|
| 1 | +#include <algorithm> |
| 2 | + |
1 | 3 | #include "catch.hpp"
|
2 | 4 | #include "datadog/json.hpp"
|
3 | 5 | #include "datadog/remote_config/remote_config.h"
|
@@ -184,10 +186,13 @@ REMOTE_CONFIG_TEST("response processing") {
|
184 | 186 |
|
185 | 187 | rc.process_response(response_json);
|
186 | 188 |
|
187 |
| - // Next payload should contains an error. |
| 189 | + // Next payload should contain an error. |
188 | 190 | const auto payload = rc.make_request_payload();
|
189 | 191 | CHECK(payload.contains("/client/state/has_error"_json_pointer) == true);
|
190 | 192 | CHECK(payload.contains("/client/state/error"_json_pointer) == true);
|
| 193 | + |
| 194 | + // targets_version should not have been updated. |
| 195 | + CHECK(payload["client"]["state"]["targets_version"] == 0); |
191 | 196 | }
|
192 | 197 |
|
193 | 198 | SECTION("update dispatch") {
|
@@ -270,6 +275,36 @@ REMOTE_CONFIG_TEST("response processing") {
|
270 | 275 | }
|
271 | 276 | }
|
272 | 277 |
|
| 278 | + SECTION("cached_target_files is correctly populated") { |
| 279 | + auto payload = rc.make_request_payload(); |
| 280 | + |
| 281 | + auto cached_target_files = payload.find("cached_target_files"); |
| 282 | + REQUIRE(cached_target_files != payload.end()); |
| 283 | + |
| 284 | + REQUIRE(cached_target_files->is_array()); |
| 285 | + REQUIRE(cached_target_files->size() == 3); |
| 286 | + |
| 287 | + std::sort(cached_target_files->begin(), cached_target_files->end(), |
| 288 | + [](const auto& a, const auto& b) { |
| 289 | + return a.at("path").template get<std::string_view>() < |
| 290 | + b.at("path").template get<std::string_view>(); |
| 291 | + }); |
| 292 | + |
| 293 | + const auto ctf = cached_target_files->at(0); |
| 294 | + REQUIRE(ctf.at("path").get<std::string_view>() == |
| 295 | + "employee/AGENT_CONFIG/test_rc_update/flare_conf"); |
| 296 | + REQUIRE(ctf.at("length").get<std::uint64_t>() == 381UL); |
| 297 | + |
| 298 | + auto hashes = ctf.at("hashes"); |
| 299 | + |
| 300 | + REQUIRE(hashes.is_array()); |
| 301 | + REQUIRE(hashes.size() == 1); |
| 302 | + |
| 303 | + const auto h = hashes.at(0); |
| 304 | + REQUIRE(h.at("algorithm").get<std::string_view>() == "sha256"); |
| 305 | + REQUIRE(h.at("hash").get<std::string_view>().size() == 64U); |
| 306 | + } |
| 307 | + |
273 | 308 | SECTION("same config update should not trigger listeners") {
|
274 | 309 | rc.process_response(response_json);
|
275 | 310 | CHECK(tracing_listener->count_on_update == 1);
|
|
0 commit comments