|
28 | 28 | #include <fcntl.h> |
29 | 29 | #include "flb_tests_runtime.h" |
30 | 30 |
|
| 31 | +#define DPATH FLB_TESTS_DATA_PATH "/data/common" |
31 | 32 | #define DEFAULT_IO_TIMEOUT 10 |
32 | 33 | #define DEFAULT_HOST "127.0.0.1" |
33 | 34 | #define DEFAULT_PORT 5180 |
@@ -117,6 +118,7 @@ static struct test_ctx *test_ctx_create(struct flb_lib_out_cb *data) |
117 | 118 | "Flush", "0.200000000", |
118 | 119 | "Grace", "1", |
119 | 120 | "Log_Level", "error", |
| 121 | + "Parsers_File", DPATH "/parsers.conf", |
120 | 122 | NULL); |
121 | 123 |
|
122 | 124 | /* Input */ |
@@ -431,10 +433,73 @@ void flb_test_format_none_separator() |
431 | 433 | test_ctx_destroy(ctx); |
432 | 434 | } |
433 | 435 |
|
| 436 | +void flb_test_format_none_with_parser() |
| 437 | +{ |
| 438 | + struct flb_lib_out_cb cb_data; |
| 439 | + struct test_ctx *ctx; |
| 440 | + struct sockaddr_in addr; |
| 441 | + flb_sockfd_t fd; |
| 442 | + int ret; |
| 443 | + int num; |
| 444 | + ssize_t w_size; |
| 445 | + char *buf = "{\"test\":\"msg\"}\n"; |
| 446 | + size_t size = strlen(buf); |
| 447 | + |
| 448 | + clear_output_num(); |
| 449 | + |
| 450 | + cb_data.cb = cb_check_result_json; |
| 451 | + cb_data.data = "\"test\":\"msg\""; |
| 452 | + |
| 453 | + ctx = test_ctx_create(&cb_data); |
| 454 | + if (!TEST_CHECK(ctx != NULL)) { |
| 455 | + TEST_MSG("test_ctx_create failed"); |
| 456 | + exit(EXIT_FAILURE); |
| 457 | + } |
| 458 | + |
| 459 | + ret = flb_output_set(ctx->flb, ctx->o_ffd, |
| 460 | + "match", "*", |
| 461 | + "format", "json", |
| 462 | + NULL); |
| 463 | + TEST_CHECK(ret == 0); |
| 464 | + |
| 465 | + ret = flb_input_set(ctx->flb, ctx->i_ffd, |
| 466 | + "format", "none", |
| 467 | + "parser", "json", |
| 468 | + NULL); |
| 469 | + TEST_CHECK(ret == 0); |
| 470 | + |
| 471 | + ret = flb_start(ctx->flb); |
| 472 | + TEST_CHECK(ret == 0); |
| 473 | + |
| 474 | + fd = init_udp(NULL, -1, &addr); |
| 475 | + if (!TEST_CHECK(fd >= 0)) { |
| 476 | + exit(EXIT_FAILURE); |
| 477 | + } |
| 478 | + |
| 479 | + w_size = sendto(fd, buf, size, 0, (const struct sockaddr *) &addr, sizeof(addr)); |
| 480 | + if (!TEST_CHECK(w_size == size)) { |
| 481 | + TEST_MSG("failed to send, errno=%d", errno); |
| 482 | + flb_socket_close(fd); |
| 483 | + test_ctx_destroy(ctx); |
| 484 | + exit(EXIT_FAILURE); |
| 485 | + } |
| 486 | + |
| 487 | + flb_time_msleep(1500); |
| 488 | + |
| 489 | + num = get_output_num(); |
| 490 | + if (!TEST_CHECK(num > 0)) { |
| 491 | + TEST_MSG("no outputs"); |
| 492 | + } |
| 493 | + |
| 494 | + flb_socket_close(fd); |
| 495 | + test_ctx_destroy(ctx); |
| 496 | +} |
| 497 | + |
434 | 498 | TEST_LIST = { |
435 | 499 | {"udp", flb_test_udp}, |
436 | 500 | {"udp_with_source_address", flb_test_udp_with_source_address}, |
437 | 501 | {"format_none", flb_test_format_none}, |
438 | 502 | {"format_none_separator", flb_test_format_none_separator}, |
| 503 | + {"format_none_with_parser", flb_test_format_none_with_parser}, |
439 | 504 | {NULL, NULL} |
440 | 505 | }; |
0 commit comments