From 66cea672662edfd2a8011530fbcd614d66d5ba63 Mon Sep 17 00:00:00 2001 From: Andrea Terzolo Date: Thu, 4 Jan 2024 16:40:07 +0100 Subject: [PATCH] cleanup(tests): use new `check_error_message` helper Signed-off-by: Andrea Terzolo --- unit_tests/engine/test_rule_loader.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/unit_tests/engine/test_rule_loader.cpp b/unit_tests/engine/test_rule_loader.cpp index 48231f33e51..3ed5aaa01c3 100644 --- a/unit_tests/engine/test_rule_loader.cpp +++ b/unit_tests/engine/test_rule_loader.cpp @@ -202,7 +202,6 @@ TEST_F(engine_loader_test, rule_override_append) "legit rule description with append"); } - TEST_F(engine_loader_test, rule_append) { std::string rules_content = R"END( @@ -228,7 +227,6 @@ TEST_F(engine_loader_test, rule_append) "(evt.type = open and proc.name = cat)"); } - TEST_F(engine_loader_test, rule_override_replace) { std::string rules_content = R"END( @@ -318,7 +316,7 @@ TEST_F(engine_loader_test, rule_incorrect_override_type) std::string rule_name = "failing_rule"; ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); - ASSERT_EQ(m_load_result_json["errors"][0]["message"], "Key 'priority' cannot be appended to, use 'replace' instead"); + ASSERT_TRUE(check_error_message("Key 'priority' cannot be appended to, use 'replace' instead")); ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["context"]["snippet"]).find("priority: append") != std::string::npos); } @@ -347,7 +345,7 @@ TEST_F(engine_loader_test, rule_incorrect_append_override) // We should have at least one warning because the 'append' flag is deprecated. ASSERT_TRUE(check_warning_message(WARNING_APPEND_MESSAGE)); - ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find(OVERRIDE_APPEND_ERROR_MESSAGE) != std::string::npos); + ASSERT_TRUE(check_error_message(OVERRIDE_APPEND_ERROR_MESSAGE)); } TEST_F(engine_loader_test, rule_override_without_rule) @@ -364,7 +362,7 @@ TEST_F(engine_loader_test, rule_override_without_rule) std::string rule_name = "failing_rule"; ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); - ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find("no rule by that name already exists") != std::string::npos); + ASSERT_TRUE(check_error_message("no rule by that name already exists")); } TEST_F(engine_loader_test, rule_override_without_field) @@ -386,7 +384,7 @@ TEST_F(engine_loader_test, rule_override_without_field) std::string rule_name = "failing_rule"; ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); - ASSERT_EQ(m_load_result_json["errors"][0]["message"], "An append override for 'condition' was specified but 'condition' is not defined"); + ASSERT_TRUE(check_error_message("An append override for 'condition' was specified but 'condition' is not defined")); } TEST_F(engine_loader_test, rule_override_extra_field) @@ -410,7 +408,7 @@ TEST_F(engine_loader_test, rule_override_extra_field) std::string rule_name = "failing_rule"; ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); - ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find("Unexpected key 'priority'") != std::string::npos); + ASSERT_TRUE(check_error_message("Unexpected key 'priority'")); } TEST_F(engine_loader_test, missing_enabled_key_with_override)