Skip to content

Commit

Permalink
tests: runtime: filter_record_modifier: add test for whitelist_keys(f…
Browse files Browse the repository at this point in the history
…luent#6200)

Signed-off-by: Takahiro Yamashita <nokute78@gmail.com>
  • Loading branch information
nokute78 authored and edsiper committed Oct 21, 2022
1 parent 6671392 commit 22fd4c2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/runtime/filter_record_modifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,52 @@ static void flb_allowlist_keys()
filter_test_destroy(ctx);
}

static void flb_whitelist_keys()
{
int len;
int ret;
int bytes;
char *p;
struct flb_lib_out_cb cb_data;
struct filter_test *ctx;
struct expect_str expect[] = {
{"\"aaa\":\"ok\"", FLB_TRUE},
{"\"bbb\":\"ok\"", FLB_TRUE},
{"\"ccc\":\"removed\"", FLB_FALSE},
{NULL, FLB_TRUE}
};

/* Create test context */
ctx = filter_test_create((void *) &cb_data);
if (!ctx) {
exit(EXIT_FAILURE);
}

/* Configure filter */
ret = flb_filter_set(ctx->flb, ctx->f_ffd,
"whitelist_key", "aaa",
"whitelist_key", "bbb",
NULL);
TEST_CHECK(ret == 0);

/* Prepare output callback with expected result */
cb_data.cb = cb_check_result;
cb_data.data = &expect;

/* Start the engine */
ret = flb_start(ctx->flb);
TEST_CHECK(ret == 0);

/* Ingest data samples */
/* The pair "ccc":"removed" should be removed */
p = "[0, {\"aaa\":\"ok\",\"ccc\":\"removed\",\"bbb\":\"ok\"}]";
len = strlen(p);
bytes = flb_lib_push(ctx->flb, ctx->i_ffd, p, len);
TEST_CHECK(bytes == len);

filter_test_destroy(ctx);
}

static void flb_remove_keys()
{
int len;
Expand Down Expand Up @@ -407,6 +453,7 @@ TEST_LIST = {
{"remove_keys" , flb_remove_keys},
{"records" , flb_records},
{"allowlist_keys" , flb_allowlist_keys},
{"whitelist_keys" , flb_whitelist_keys},
{"multiple" , flb_multiple},
{"exclusive_setting" , flb_exclusive_setting},
{NULL, NULL}
Expand Down

0 comments on commit 22fd4c2

Please sign in to comment.