test: runtime: filter_nest: add lifted testcase filter_nest(#1434)
To check if flter_nest drops event if it is not mached.
@@ -12,10 +12,12 @@ int num_output = 0;
/* Test functions */
void flb_test_filter_nest_single(void);
void flb_test_filter_nest_multi_nest(void);
+void flb_test_filter_nest_multi_lift(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},
{NULL, NULL}
};
@@ -154,6 +156,79 @@ void flb_test_filter_nest_multi_nest(void)
flb_destroy(ctx);
}
+void flb_test_filter_nest_multi_lift(void)
+{
+ int ret;
+ int bytes;
+ char *p;
+ flb_ctx_t *ctx;
+ int in_ffd;
+ int out_ffd;
+ int filter_ffd;
+ struct flb_lib_out_cb cb_data;
+
+ int count = 0; // should be number of events.
+ int expected = 2;
+
+ clear_output_num();
+
+ 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_count;
+ 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",
+ "Nested_under", "nested",
+ 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\": {\"child\":\"nested data\"}, \"not_nestd\":\"not nested data\" }]";
+ bytes = flb_lib_push(ctx, in_ffd, p, strlen(p));
+ TEST_CHECK(bytes == strlen(p));
+
+ p = "[1448403341, {\"not_nest\":\"dummy data\", \"extra\":\"dummy more data\"}]";
+ bytes = flb_lib_push(ctx, in_ffd, p, strlen(p));
+ TEST_CHECK(bytes == strlen(p));
+
+ sleep(1); /* waiting flush */
+ count = get_output_num();
+
+ TEST_CHECK_(count == expected, "Expected number of events %d, got %d", expected, count );
+
+ flb_stop(ctx);
+ flb_destroy(ctx);
+}
+
void flb_test_filter_nest_single(void)
{
int ret;
