adamdebreceni commented on code in PR #1692: URL: https://github.com/apache/nifi-minifi-cpp/pull/1692#discussion_r1423912281
########## libminifi/test/Utils.h: ########## @@ -48,23 +48,45 @@ using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi::test::utils { +struct JsonContext { + const JsonContext* parent{nullptr}; + std::string_view member; Review Comment: moved this into an internal namespace ########## libminifi/test/Utils.h: ########## @@ -48,23 +48,45 @@ using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi::test::utils { +struct JsonContext { + const JsonContext* parent{nullptr}; + std::string_view member; + + std::string path() const { + if (!parent) { + return "/"; + } + return minifi::utils::StringUtils::join_pack(parent->path(), member, "/"); + } +}; + +#define REQUIRE_WARN(cond, msg) if (!(cond)) {WARN(msg); REQUIRE(cond);} + // carries out a loose match on objects, i.e. it doesn't matter if the // actual object has extra fields than expected -void matchJSON(const rapidjson::Value& actual, const rapidjson::Value& expected) { +void matchJSON(const JsonContext& ctx, const rapidjson::Value& actual, const rapidjson::Value& expected, bool strict = false) { if (expected.IsObject()) { - REQUIRE(actual.IsObject()); + REQUIRE_WARN(actual.IsObject(), fmt::format("Expected object at {}", ctx.path())); for (const auto& expected_member : expected.GetObject()) { - REQUIRE(actual.HasMember(expected_member.name)); - matchJSON(actual[expected_member.name], expected_member.value); + std::string_view name{expected_member.name.GetString(), expected_member.name.GetStringLength()}; + REQUIRE_WARN(actual.HasMember(expected_member.name), fmt::format("Expected member '{}' at {}", name, ctx.path())); + matchJSON(JsonContext{.parent = &ctx, .member = name}, actual[expected_member.name], expected_member.value, strict); + } + if (strict) { + for (const auto& actual_member : actual.GetObject()) { + std::string_view name{actual_member.name.GetString(), actual_member.name.GetStringLength()}; + REQUIRE_WARN(expected.HasMember(actual_member.name), fmt::format("Did not expect member '{}' at {}", name, ctx.path())); + matchJSON(JsonContext{.parent = &ctx, .member = name}, actual_member.value, expected[actual_member.name], strict); Review Comment: good catch, removed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org