diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:20:02 +0000 |
commit | 58daab21cd043e1dc37024a7f99b396788372918 (patch) | |
tree | 96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /fluent-bit/tests/internal/file.c | |
parent | Releasing debian version 1.43.2-1. (diff) | |
download | netdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz netdata-58daab21cd043e1dc37024a7f99b396788372918.zip |
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/tests/internal/file.c')
-rw-r--r-- | fluent-bit/tests/internal/file.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/fluent-bit/tests/internal/file.c b/fluent-bit/tests/internal/file.c new file mode 100644 index 000000000..974c26687 --- /dev/null +++ b/fluent-bit/tests/internal/file.c @@ -0,0 +1,48 @@ +#include <fluent-bit/flb_file.h> +#include <fluent-bit/flb_sds.h> +#include <string.h> + +#include "flb_tests_internal.h" +#include "fluent-bit/stream_processor/flb_sp.h" + +#define TEXT_FILE FLB_TESTS_DATA_PATH "/data/file/text_file.txt" +#define EMPTY_FILE FLB_TESTS_DATA_PATH "/data/file/empty_file.txt" + +static void check_equals(flb_sds_t result, const char *expected) +{ + size_t expected_len = strlen(expected); + size_t result_len = flb_sds_len(result); + TEST_CHECK(expected_len == result_len); + TEST_MSG("Expected length: %zu", expected_len); + TEST_MSG("Actual length: %zu", result_len); + TEST_CHECK(memcmp(result, expected, expected_len) == 0); + TEST_MSG("Expected: %s", expected); + TEST_MSG("Actual: %s", result); +} + +static void test_file_read_text_file() +{ + flb_sds_t result = flb_file_read(TEXT_FILE); + check_equals(result, "Some text file\n\nline 3\n\nline 5\n"); + flb_sds_destroy(result); +} + +static void test_file_read_empty_file() +{ + flb_sds_t result = flb_file_read(EMPTY_FILE); + check_equals(result, ""); + flb_sds_destroy(result); +} + +static void test_file_read_missing() +{ + flb_sds_t result = flb_file_read(TEXT_FILE ".missing"); + TEST_CHECK(result == NULL); +} + +TEST_LIST = { + { "file_read_text_file" , test_file_read_text_file}, + { "file_read_empty_file" , test_file_read_empty_file}, + { "file_read_missing" , test_file_read_missing}, + { 0 } +}; |