From 0d6fea1ecc2ec2b5b096955fca4160caab11f705 Mon Sep 17 00:00:00 2001 From: Patrick Stephens Date: Mon, 16 Dec 2024 15:34:31 +0000 Subject: [PATCH] in_calyptia_fleet: refactor to expose functions Signed-off-by: Patrick Stephens --- plugins/in_calyptia_fleet/in_calyptia_fleet.c | 17 ++++++----- plugins/in_calyptia_fleet/in_calyptia_fleet.h | 6 +--- tests/runtime/in_calyptia_fleet_test.c | 29 +++++++------------ 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.c b/plugins/in_calyptia_fleet/in_calyptia_fleet.c index e1af9b26e22..8f2e4484bcb 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.c +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.c @@ -60,6 +60,10 @@ #define DEFAULT_MAX_HTTP_BUFFER_SIZE "10485760" +static int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx); +static int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, + time_t timestamp); + #ifndef FLB_SYSTEM_WINDOWS static int is_link(const char *path) { @@ -1664,7 +1668,7 @@ flb_sds_t fleet_config_get(struct flb_in_calyptia_fleet_config *ctx) return NULL; } - buf = flb_sds_create_size(2048); + buf = flb_sds_create_size(CALYPTIA_MAX_DIR_SIZE); if (!buf) { return NULL; @@ -1754,7 +1758,7 @@ static int create_fleet_header(struct flb_in_calyptia_fleet_config *ctx) return rc; } -static int get_calyptia_fleet_config(struct flb_in_calyptia_fleet_config *ctx) +int get_calyptia_fleet_config(struct flb_in_calyptia_fleet_config *ctx) { flb_sds_t cfgname; flb_sds_t cfgnewname; @@ -1804,7 +1808,7 @@ static int get_calyptia_fleet_config(struct flb_in_calyptia_fleet_config *ctx) /* new file created! */ if (ret == 1) { - get_calyptia_files(ctx, ctx->fleet_files_url, time_last_modified); + get_calyptia_files(ctx, time_last_modified); cfgname = time_fleet_config_filename(ctx, time_last_modified); @@ -1926,7 +1930,7 @@ static int fleet_mkdir(struct flb_in_calyptia_fleet_config *ctx, time_t timestam return ret; } -int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx) +static int fleet_cur_chdir(struct flb_in_calyptia_fleet_config *ctx) { flb_sds_t fleetcurdir; int ret; @@ -2117,14 +2121,13 @@ static int create_fleet_files(struct flb_in_calyptia_fleet_config *ctx, return 0; } -int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, - const char *url, +static int get_calyptia_files(struct flb_in_calyptia_fleet_config *ctx, time_t timestamp) { struct flb_http_client *client; int ret = -1; - if (ctx == NULL || url == NULL) { + if (ctx == NULL || ctx->fleet_files_url == NULL) { return -1; } diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.h b/plugins/in_calyptia_fleet/in_calyptia_fleet.h index ae7d19a20d6..ed97c73f376 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.h +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.h @@ -75,10 +75,6 @@ flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx, char * #define old_fleet_config_filename(a) fleet_config_filename((a), "old") #define hdr_fleet_config_filename(a) fleet_config_filename((a), "header") -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); +int get_calyptia_fleet_config(struct flb_in_calyptia_fleet_config *ctx); #endif /* FLB_IN_CALYPTIA_FLEET_H */ diff --git a/tests/runtime/in_calyptia_fleet_test.c b/tests/runtime/in_calyptia_fleet_test.c index 0f7287dddfe..c9cd8cb1da2 100644 --- a/tests/runtime/in_calyptia_fleet_test.c +++ b/tests/runtime/in_calyptia_fleet_test.c @@ -1,15 +1,12 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + #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); +int get_calyptia_fleet_config(struct flb_in_calyptia_fleet_config *ctx); /* Test context structure */ struct test_context { @@ -71,6 +68,7 @@ static void cleanup_test_context(struct test_context *t_ctx) 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->fleet_files_url) flb_free(t_ctx->ctx->fleet_files_url); if (t_ctx->ctx->ins) flb_free(t_ctx->ctx->ins); flb_free(t_ctx->ctx); @@ -84,7 +82,7 @@ static void cleanup_test_context(struct test_context *t_ctx) flb_free(t_ctx); } -static void test_in_fleet_toml_format() { +static void test_in_fleet_format() { struct test_context *t_ctx = init_test_context(); TEST_CHECK(t_ctx != NULL); @@ -98,33 +96,26 @@ static void test_in_fleet_toml_format() { TEST_MSG("fleet_config_filename expected=%s got=%s", expectedValue, value); TEST_CHECK(value && strcmp(value, expectedValue) == 0); flb_sds_destroy(value); - - 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); + value = NULL; /* Ensure we create YAML files if configured to do so */ t_ctx->ctx->fleet_config_legacy_format = FLB_FALSE; - char expectedValue[CALYPTIA_MAX_DIR_SIZE]; - int ret = sprintf(expectedValue, "%s/%s/%s/test.yaml", FLEET_DEFAULT_CONFIG_DIR, t_ctx->ctx->machine_id, t_ctx->ctx->fleet_name); + ret = sprintf(expectedValue, "%s/%s/%s/test.yaml", FLEET_DEFAULT_CONFIG_DIR, t_ctx->ctx->machine_id, t_ctx->ctx->fleet_name); TEST_CHECK(ret > 0); - flb_sds_t value = fleet_config_filename( t_ctx->ctx, "test" ); + value = fleet_config_filename( t_ctx->ctx, "test" ); TEST_CHECK(value != NULL); TEST_MSG("fleet_config_filename expected=%s got=%s", expectedValue, value); TEST_CHECK(value && strcmp(value, expectedValue) == 0); flb_sds_destroy(value); + value = 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}, + {"in_calyptia_fleet_format", test_in_fleet_format}, {NULL, NULL} }; \ No newline at end of file