Skip to content

Commit afc3669

Browse files
committed
wasm: filter: msgpack: Add a test case which uses msgpack payload
Signed-off-by: Hiroshi Hatake <hatake@calyptia.com>
1 parent 61da4d3 commit afc3669

File tree

6 files changed

+566
-0
lines changed

6 files changed

+566
-0
lines changed
Binary file not shown.

tests/runtime/filter_wasm.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,73 @@ void flb_test_drop_all_records(void)
458458
}
459459

460460

461+
void flb_test_append_kv_on_msgpack(void)
462+
{
463+
int ret;
464+
flb_ctx_t *ctx;
465+
int in_ffd;
466+
int out_ffd;
467+
int filter_ffd;
468+
char *output = NULL;
469+
char *input = "[0, {\"key\":\"val\"}]";
470+
char *result;
471+
struct flb_lib_out_cb cb_data;
472+
473+
/* clear previous output */
474+
clear_output();
475+
476+
/* Create context, flush every second (some checks omitted here) */
477+
ctx = flb_create();
478+
flb_service_set(ctx, "flush", FLUSH_INTERVAL, "grace", "1", NULL);
479+
480+
/* Prepare output callback context*/
481+
cb_data.cb = callback_test;
482+
cb_data.data = NULL;
483+
484+
/* Filter */
485+
filter_ffd = flb_filter(ctx, (char *) "wasm", NULL);
486+
TEST_CHECK(filter_ffd >= 0);
487+
ret = flb_filter_set(ctx, filter_ffd,
488+
"Match", "*",
489+
"event_format", "msgpack",
490+
"wasm_path", DPATH_WASM "/msgpack/filter_rust_mp.wasm",
491+
"function_name", "rust_filter_mp",
492+
NULL);
493+
494+
/* Input */
495+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
496+
flb_input_set(ctx, in_ffd, "tag", "test.wasm.mp", NULL);
497+
TEST_CHECK(in_ffd >= 0);
498+
499+
/* Lib output */
500+
out_ffd = flb_output(ctx, (char *) "lib", (void *)&cb_data);
501+
TEST_CHECK(out_ffd >= 0);
502+
flb_output_set(ctx, out_ffd,
503+
"match", "test.wasm.mp",
504+
"format", "json",
505+
NULL);
506+
507+
ret = flb_start(ctx);
508+
TEST_CHECK(ret==0);
509+
510+
flb_lib_push(ctx, in_ffd, input, strlen(input));
511+
wait_with_timeout(2000, &output);
512+
result = strstr(output, "\"platform\":\"wasm\"");
513+
TEST_CHECK(result != NULL);
514+
515+
/* clean up */
516+
flb_lib_free(output);
517+
518+
flb_stop(ctx);
519+
flb_destroy(ctx);
520+
}
521+
461522
TEST_LIST = {
462523
{"hello_world", flb_test_helloworld},
463524
{"append_tag", flb_test_append_tag},
464525
{"numeric_records", flb_test_numerics_records},
465526
{"array_contains_null", flb_test_array_contains_null},
466527
{"drop_all_records", flb_test_drop_all_records},
528+
{"append_kv_on_msgpack_format", flb_test_append_kv_on_msgpack},
467529
{NULL, NULL}
468530
};

0 commit comments

Comments
 (0)