From 7c8209ed8e6e1aaf439039977b8eb388622c29c9 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Tue, 8 Oct 2024 08:47:29 +0000 Subject: [PATCH] update(tests): add tests for plugin init_config Signed-off-by: Luca Guerra --- .../falco/test_configuration_schema.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/unit_tests/falco/test_configuration_schema.cpp b/unit_tests/falco/test_configuration_schema.cpp index 2774fca2f52..85da84c5987 100644 --- a/unit_tests/falco/test_configuration_schema.cpp +++ b/unit_tests/falco/test_configuration_schema.cpp @@ -18,6 +18,7 @@ limitations under the License. #include #include #include +#include #define EXPECT_VALIDATION_STATUS(res, status) \ do { \ @@ -102,8 +103,13 @@ TEST(Configuration, plugin_init_config) { sslCertificate: /etc/falco/falco.pem )"; + auto plugin_config_json = nlohmann::json::parse( + R"({"maxEventSize": 262144, "sslCertificate": "/etc/falco/falco.pem"})"); + EXPECT_NO_THROW(res = falco_config.init_from_content(config, {})); EXPECT_VALIDATION_STATUS(res, yaml_helper::validation_ok); + auto parsed_init_config = nlohmann::json::parse(falco_config.m_plugins[0].m_init_config); + EXPECT_EQ(parsed_init_config, plugin_config_json); config = R"( plugins: @@ -114,6 +120,30 @@ TEST(Configuration, plugin_init_config) { EXPECT_NO_THROW(res = falco_config.init_from_content(config, {})); EXPECT_VALIDATION_STATUS(res, yaml_helper::validation_ok); + parsed_init_config = nlohmann::json::parse(falco_config.m_plugins[0].m_init_config); + EXPECT_EQ(parsed_init_config, plugin_config_json); + + config = R"( +plugins: + - name: k8saudit + library_path: libk8saudit.so + init_config: "" +)"; + + EXPECT_NO_THROW(res = falco_config.init_from_content(config, {})); + EXPECT_VALIDATION_STATUS(res, yaml_helper::validation_ok); + EXPECT_EQ(falco_config.m_plugins[0].m_init_config, ""); + + config = R"( +plugins: + - name: k8saudit + library_path: libk8saudit.so + init_config: null +)"; + + EXPECT_NO_THROW(res = falco_config.init_from_content(config, {})); + EXPECT_VALIDATION_STATUS(res, yaml_helper::validation_ok); + EXPECT_EQ(falco_config.m_plugins[0].m_init_config, ""); } TEST(Configuration, schema_yaml_helper_validator) {