Skip to content

Commit

Permalink
cleanup(tests): use new check_error_message helper
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 committed Jan 4, 2024
1 parent 7484bde commit 66cea67
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions unit_tests/engine/test_rule_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 66cea67

Please sign in to comment.