Skip to content

Commit

Permalink
in_tcp: test: Add a source IP injection test case
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Jul 10, 2023
1 parent b93950f commit 973ab52
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/runtime/in_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,69 @@ void flb_test_tcp()
test_ctx_destroy(ctx);
}

void flb_test_tcp_with_source_address()
{
struct flb_lib_out_cb cb_data;
struct test_ctx *ctx;
flb_sockfd_t fd;
int ret;
int num;
ssize_t w_size;

char *buf = "{\"test\":\"msg\"}";
size_t size = strlen(buf);

clear_output_num();

cb_data.cb = cb_check_result_json;
cb_data.data = "\"test\":\"msg\",\"source_host\":\"tcp://";

ctx = test_ctx_create(&cb_data);
if (!TEST_CHECK(ctx != NULL)) {
TEST_MSG("test_ctx_create failed");
exit(EXIT_FAILURE);
}

ret = flb_input_set(ctx->flb, ctx->i_ffd,
"source_address_key", "source_host",
NULL);
TEST_CHECK(ret == 0);

ret = flb_output_set(ctx->flb, ctx->o_ffd,
"match", "*",
"format", "json",
NULL);
TEST_CHECK(ret == 0);

/* Start the engine */
ret = flb_start(ctx->flb);
TEST_CHECK(ret == 0);

/* use default host/port */
fd = connect_tcp(NULL, -1);
if (!TEST_CHECK(fd >= 0)) {
exit(EXIT_FAILURE);
}

w_size = send(fd, buf, size, 0);
if (!TEST_CHECK(w_size == size)) {
TEST_MSG("failed to send, errno=%d", errno);
flb_socket_close(fd);
exit(EXIT_FAILURE);
}

/* waiting to flush */
flb_time_msleep(1500);

num = get_output_num();
if (!TEST_CHECK(num > 0)) {
TEST_MSG("no outputs");
}

flb_socket_close(fd);
test_ctx_destroy(ctx);
}

void flb_test_tcp_with_tls()
{
struct flb_connection *client_connection;
Expand Down Expand Up @@ -552,6 +615,7 @@ void flb_test_issue_5336()

TEST_LIST = {
{"tcp", flb_test_tcp},
{"tcp_with_source_address", flb_test_tcp_with_source_address},
{"tcp_with_tls", flb_test_tcp_with_tls},
{"format_none", flb_test_format_none},
{"format_none_separator", flb_test_format_none_separator},
Expand Down

0 comments on commit 973ab52

Please sign in to comment.