Skip to content

Commit

Permalink
tests: runtime: filter_nest: add test case for add_prefix (#8372)
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and pwhelan committed Jan 16, 2024
1 parent decab72 commit f1a1641
Showing 1 changed file with 72 additions and 0 deletions.
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);
}

0 comments on commit f1a1641

Please sign in to comment.