Skip to content

Commit

Permalink
tests: runtime: in_calyptia_fleet: add placeholders
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Stephens <[email protected]>
  • Loading branch information
patrick-stephens committed Dec 16, 2024
1 parent 5ef6296 commit fc1cbbd
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 42 deletions.
6 changes: 3 additions & 3 deletions plugins/in_calyptia_fleet/in_calyptia_fleet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions plugins/in_calyptia_fleet/in_calyptia_fleet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 3 additions & 1 deletion tests/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
35 changes: 0 additions & 35 deletions tests/runtime/custom_calyptia_input_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
106 changes: 106 additions & 0 deletions tests/runtime/in_calyptia_fleet_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <fluent-bit.h>
#include <fluent-bit/calyptia/calyptia_constants.h>
#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}
};

0 comments on commit fc1cbbd

Please sign in to comment.