diff --git a/tests/runtime/filter_nest.c b/tests/runtime/filter_nest.c index 36e6a3fe795..f9b43814f0f 100644 --- a/tests/runtime/filter_nest.c +++ b/tests/runtime/filter_nest.c @@ -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} }; @@ -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); +}