Skip to content

Commit

Permalink
update(tests): add tests for plugin init_config
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Guerra <[email protected]>
  • Loading branch information
LucaGuerra authored and poiana committed Oct 8, 2024
1 parent 6721a6b commit a754601
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions unit_tests/falco/test_configuration_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
#include <gtest/gtest.h>
#include <falco/configuration.h>
#include <falco_test_var.h>
#include <nlohmann/json.hpp>

#define EXPECT_VALIDATION_STATUS(res, status) \
do { \
Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand Down

0 comments on commit a754601

Please sign in to comment.