Skip to content

Commit b860035

Browse files
committed
tests: in_udp: Add a test case for parser capability
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 6450899 commit b860035

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

tests/runtime/in_udp.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <fcntl.h>
2929
#include "flb_tests_runtime.h"
3030

31+
#define DPATH FLB_TESTS_DATA_PATH "/data/common"
3132
#define DEFAULT_IO_TIMEOUT 10
3233
#define DEFAULT_HOST "127.0.0.1"
3334
#define DEFAULT_PORT 5180
@@ -117,6 +118,7 @@ static struct test_ctx *test_ctx_create(struct flb_lib_out_cb *data)
117118
"Flush", "0.200000000",
118119
"Grace", "1",
119120
"Log_Level", "error",
121+
"Parsers_File", DPATH "/parsers.conf",
120122
NULL);
121123

122124
/* Input */
@@ -431,10 +433,73 @@ void flb_test_format_none_separator()
431433
test_ctx_destroy(ctx);
432434
}
433435

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+
434498
TEST_LIST = {
435499
{"udp", flb_test_udp},
436500
{"udp_with_source_address", flb_test_udp_with_source_address},
437501
{"format_none", flb_test_format_none},
438502
{"format_none_separator", flb_test_format_none_separator},
503+
{"format_none_with_parser", flb_test_format_none_with_parser},
439504
{NULL, NULL}
440505
};

0 commit comments

Comments
 (0)