Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: runtime: filter_nest: add test case for add_prefix #8372

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions tests/runtime/filter_nest.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ int num_output = 0;
void flb_test_filter_nest_single(void);
void flb_test_filter_nest_multi_nest(void);
void flb_test_filter_nest_multi_lift(void);
void flb_test_filter_nest_add_prefix(void);
/* Test list */
TEST_LIST = {
{"single", flb_test_filter_nest_single },
{"multiple events are not dropped(nest)", flb_test_filter_nest_multi_nest},
{"multiple events are not dropped(lift)", flb_test_filter_nest_multi_lift},
{"add_prefix", flb_test_filter_nest_add_prefix},
{NULL, NULL}
};

Expand Down Expand Up @@ -300,3 +302,73 @@ void flb_test_filter_nest_single(void)
flb_stop(ctx);
flb_destroy(ctx);
}

void flb_test_filter_nest_add_prefix(void)
{
int ret;
int bytes;
char *p, *output, *expected;
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;
int filter_ffd;
struct flb_lib_out_cb cb_data;

ctx = flb_create();
flb_service_set(ctx,
"Flush", "1",
"Grace", "1",
"Log_Level", "debug",
NULL);

/* Input */
in_ffd = flb_input(ctx, (char *) "lib", NULL);
TEST_CHECK(in_ffd >= 0);
flb_input_set(ctx, in_ffd, "tag", "test", NULL);

/* Prepare output callback context*/
cb_data.cb = callback_test;
cb_data.data = NULL;

/* Filter */
filter_ffd = flb_filter(ctx, (char *) "nest", NULL);
TEST_CHECK(filter_ffd >= 0);

ret = flb_filter_set(ctx, filter_ffd,
"Match", "*",
"Operation", "lift",
"Nest_under", "nested_key",
"Add_prefix", "_nested_key.",
NULL);

TEST_CHECK(ret == 0);


/* Output */
out_ffd = flb_output(ctx, (char *) "lib", (void *) &cb_data);
TEST_CHECK(out_ffd >= 0);
flb_output_set(ctx, out_ffd,
"match", "test",
"format", "json",
NULL);

ret = flb_start(ctx);
TEST_CHECK(ret == 0);

p = "[1448403340, {\"nested_key\":{\"key\":\"value\"}}]";
bytes = flb_lib_push(ctx, in_ffd, p, strlen(p));
TEST_CHECK(bytes == strlen(p));

flb_time_msleep(1500); /* waiting flush */
output = get_output();

TEST_CHECK_(output != NULL, "Expected output to not be NULL");

if (output != NULL) {
expected = "\"_nested_key.key\":\"value\"}]";
TEST_CHECK_(strstr(output, expected) != NULL, "Expected output to contain '%s', got '%s'", expected, output);
free(output);
}
flb_stop(ctx);
flb_destroy(ctx);
}
Loading