From fc1cbbdc4fd28c912370292201955acfa1429032 Mon Sep 17 00:00:00 2001 From: Patrick Stephens Date: Mon, 16 Dec 2024 11:41:14 +0000 Subject: [PATCH] tests: runtime: in_calyptia_fleet: add placeholders Signed-off-by: Patrick Stephens --- plugins/in_calyptia_fleet/in_calyptia_fleet.c | 6 +- plugins/in_calyptia_fleet/in_calyptia_fleet.h | 6 +- tests/runtime/CMakeLists.txt | 4 +- tests/runtime/custom_calyptia_input_test.c | 35 ------ tests/runtime/in_calyptia_fleet_test.c | 106 ++++++++++++++++++ 5 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 tests/runtime/in_calyptia_fleet_test.c diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.c b/plugins/in_calyptia_fleet/in_calyptia_fleet.c index 3d4de1fe9ae..c1cedab3335 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.c +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.c @@ -188,7 +188,7 @@ static flb_sds_t generate_base_fleet_directory(struct flb_in_calyptia_fleet_conf ctx->config_dir, ctx->machine_id, ctx->fleet_id); } -static flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx, char *fname) +flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx, char *fname) { flb_sds_t cfgname = NULL; flb_sds_t ret; @@ -1921,7 +1921,7 @@ static int fleet_mkdir(struct flb_in_calyptia_fleet_config *ctx, time_t timestam return ret; } -static int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx) +int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx) { flb_sds_t fleetcurdir; int ret; @@ -2112,7 +2112,7 @@ static int create_fleet_files(struct flb_in_calyptia_fleet_config *ctx, return 0; } -static int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, +int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, const char *url, time_t timestamp) { diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.h b/plugins/in_calyptia_fleet/in_calyptia_fleet.h index 315228edb7d..ae7d19a20d6 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.h +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.h @@ -68,17 +68,17 @@ struct reload_ctx { flb_sds_t cfg_path; }; -static flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx, char *fname); +flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx, char *fname); #define new_fleet_config_filename(a) fleet_config_filename((a), "new") #define cur_fleet_config_filename(a) fleet_config_filename((a), "cur") #define old_fleet_config_filename(a) fleet_config_filename((a), "old") #define hdr_fleet_config_filename(a) fleet_config_filename((a), "header") -static int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, +int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, const char *url, time_t timestamp); -static int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx); +int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx); #endif /* FLB_IN_CALYPTIA_FLEET_H */ diff --git a/tests/runtime/CMakeLists.txt b/tests/runtime/CMakeLists.txt index 7c5143cbfca..49ed0e0cf5d 100644 --- a/tests/runtime/CMakeLists.txt +++ b/tests/runtime/CMakeLists.txt @@ -73,6 +73,7 @@ if (FLB_CUSTOM_CALYPTIA) "custom_calyptia_test.c" "custom_calyptia_registration_retry_test.c" "custom_calyptia_input_test.c" + "in_calyptia_fleet_test.c" ) foreach(TEST_SOURCE ${CALYPTIA_TESTS}) @@ -82,6 +83,7 @@ if (FLB_CUSTOM_CALYPTIA) add_executable(${TEST_TARGET} ${TEST_SOURCE} "../../plugins/custom_calyptia/calyptia.c" + "../../plugins/in_calyptia_fleet/in_calyptia_fleet.c" ) target_link_libraries(${TEST_TARGET} @@ -113,7 +115,7 @@ if(FLB_IN_EBPF) # Function to create eBPF handler tests function(add_ebpf_handler_test name source_file handler_file) set(TEST_TARGET "flb-rt-in_ebpf_${name}_handler") - + # Add executable add_executable(${TEST_TARGET} ${source_file} diff --git a/tests/runtime/custom_calyptia_input_test.c b/tests/runtime/custom_calyptia_input_test.c index 387d241cd16..7b8be6b2a77 100644 --- a/tests/runtime/custom_calyptia_input_test.c +++ b/tests/runtime/custom_calyptia_input_test.c @@ -277,44 +277,9 @@ static void test_calyptia_machine_id_generation() { cleanup_test_context(t_ctx); } -static void test_calyptia_config_format() { - struct test_context *t_ctx = init_test_context(); - TEST_CHECK(t_ctx != NULL); - - int ret = set_fleet_input_properties(t_ctx->ctx, t_ctx->fleet); - TEST_CHECK(ret == 0); - - /* Verify properties were set correctly */ - const char *value; - char *expectedValue = flb_strdup("on"); - - /* Default is true */ - value = flb_input_get_property("fleet_config_legacy_format", t_ctx->fleet); - TEST_CHECK(value != NULL); - TEST_MSG("fleet_config_legacy_format default expected=%s got=%s", expectedValue, value); - TEST_CHECK(value && strcasecmp(value, expectedValue) == 0); - - /* Check for change to disabling */ - t_ctx->ctx->fleet_config_legacy_format = FLB_FALSE; - ret = set_fleet_input_properties(t_ctx->ctx, t_ctx->fleet); - TEST_CHECK(ret == 0); - - flb_free(expectedValue); - expectedValue = flb_strdup("off"); - - value = flb_input_get_property("fleet_config_legacy_format", t_ctx->fleet); - TEST_CHECK(value != NULL); - TEST_MSG("fleet_config_legacy_format changed expected=%s got=%s", expectedValue, value); - TEST_CHECK(value && strcasecmp(value, expectedValue) == 0); - - flb_free(expectedValue); - cleanup_test_context(t_ctx); -} - /* Define test list */ TEST_LIST = { {"set_fleet_input_properties", test_set_fleet_input_properties}, {"machine_id_generation", test_calyptia_machine_id_generation}, - {"set_fleet_config_format", test_calyptia_config_format}, {NULL, NULL} }; \ No newline at end of file diff --git a/tests/runtime/in_calyptia_fleet_test.c b/tests/runtime/in_calyptia_fleet_test.c new file mode 100644 index 00000000000..873842d3a0c --- /dev/null +++ b/tests/runtime/in_calyptia_fleet_test.c @@ -0,0 +1,106 @@ +#include +#include +#include "flb_tests_runtime.h" +#include "../../plugins/in_calyptia_fleet/in_calyptia_fleet.h" + +flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx, char *fname); + +int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, + const char *url, + time_t timestamp); + +int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx); + +/* Test context structure */ +struct test_context { + struct flb_in_calyptia_fleet_config *ctx; + struct flb_config *config; +}; + +/* Initialize test context */ +static struct test_context *init_test_context() +{ + struct test_context *t_ctx = flb_calloc(1, sizeof(struct test_context)); + if (!t_ctx) { + return NULL; + } + + t_ctx->config = flb_config_init(); + if (!t_ctx->config) { + flb_free(t_ctx); + return NULL; + } + + t_ctx->ctx = flb_calloc(1, sizeof(struct flb_in_calyptia_fleet_config)); + if (!t_ctx->ctx) { + flb_config_exit(t_ctx->config); + flb_free(t_ctx); + return NULL; + } + + /* Initialize plugin instance for logging */ + t_ctx->ctx->ins = flb_calloc(1, sizeof(struct flb_input_instance)); + if (!t_ctx->ctx->ins) { + flb_free(t_ctx->ctx); + flb_config_exit(t_ctx->config); + flb_free(t_ctx); + return NULL; + } + + /* Initialize test values in ctx */ + t_ctx->ctx->api_key = flb_strdup("test_api_key"); + t_ctx->ctx->fleet_id = flb_strdup("test_fleet_id"); + + t_ctx->ctx->fleet_name = flb_strdup("test_fleet"); + t_ctx->ctx->machine_id = flb_strdup("test_machine_id"); + + t_ctx->ctx->fleet_config_legacy_format = FLB_TRUE; + + return t_ctx; +} + +static void cleanup_test_context(struct test_context *t_ctx) +{ + if (!t_ctx) { + return; + } + + if (t_ctx->ctx) { + if (t_ctx->ctx->api_key) flb_free(t_ctx->ctx->api_key); + if (t_ctx->ctx->fleet_id) flb_free(t_ctx->ctx->fleet_id); + + if (t_ctx->ctx->fleet_name) flb_free(t_ctx->ctx->fleet_name); + if (t_ctx->ctx->machine_id) flb_free(t_ctx->ctx->machine_id); + + if (t_ctx->ctx->ins) flb_free(t_ctx->ctx->ins); + flb_free(t_ctx->ctx); + } + + if (t_ctx->config) { + /* Destroy the config which will cleanup any remaining instances */ + flb_config_exit(t_ctx->config); + } + + flb_free(t_ctx); +} + +static void test_in_fleet_toml_format() { + struct test_context *t_ctx = init_test_context(); + TEST_CHECK(t_ctx != NULL); + + cleanup_test_context(t_ctx); +} + +static void test_in_fleet_yaml_format() { + struct test_context *t_ctx = init_test_context(); + TEST_CHECK(t_ctx != NULL); + + cleanup_test_context(t_ctx); +} + +/* Define test list */ +TEST_LIST = { + {"in_calyptia_fleet_toml_format", test_in_fleet_toml_format}, + {"in_calyptia_fleet_yaml_format", test_in_fleet_yaml_format}, + {NULL, NULL} +}; \ No newline at end of file