Skip to content

Commit

Permalink
tests: Introduce a basic test for out_kafka
Browse files Browse the repository at this point in the history
Create a simple test for the out_kafka plugin that creates the
context and tears it down.

Signed-off-by: Holger Hans Peter Freyther <[email protected]>
  • Loading branch information
zecke committed Sep 21, 2024
1 parent 276e03a commit a8b47fd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ if(FLB_IN_LIB)
FLB_RT_TEST(FLB_OUT_FLOWCOUNTER "out_flowcounter.c")
FLB_RT_TEST(FLB_OUT_FORWARD "out_forward.c")
FLB_RT_TEST(FLB_OUT_HTTP "out_http.c")
FLB_RT_TEST(FLB_OUT_KAFKA "out_kafka.c")
FLB_RT_TEST(FLB_OUT_LIB "out_lib.c")
FLB_RT_TEST(FLB_OUT_LOKI "out_loki.c")
FLB_RT_TEST(FLB_OUT_NULL "out_null.c")
Expand Down
49 changes: 49 additions & 0 deletions tests/runtime/out_kafka.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

#include <fluent-bit.h>
#include "flb_tests_runtime.h"

/* Test data */
#include "data/td/json_td.h"


void flb_test_raw_format()
{
int ret;
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;


ctx = flb_create();

in_ffd = flb_input(ctx, (char *) "lib", NULL);
TEST_CHECK(in_ffd >= 0);
flb_input_set(ctx, in_ffd, "tag", "test", NULL);

/* Kafka output */
out_ffd = flb_output(ctx, (char *) "kafka", NULL);
TEST_CHECK(out_ffd >= 0);
flb_output_set(ctx, out_ffd, "match", "test", NULL);

/* Switch to raw mode and select a key */
flb_output_set(ctx, out_ffd, "format", "raw", NULL);
flb_output_set(ctx, out_ffd, "raw_log_key", "key_0", NULL);
flb_output_set(ctx, out_ffd, "topics", "test", NULL);
flb_output_set(ctx, out_ffd, "brokers", "127.0.0.1:111", NULL);
flb_output_set(ctx, out_ffd, "queue_full_retries", "1", NULL);

ret = flb_start(ctx);
TEST_CHECK(ret == 0);

flb_lib_push(ctx, in_ffd, (char *) JSON_TD, (int) sizeof(JSON_TD) - 1);

sleep(2);
flb_stop(ctx);
flb_destroy(ctx);
}

TEST_LIST = {
{ "raw_format", flb_test_raw_format },
{ NULL, NULL },
};

0 comments on commit a8b47fd

Please sign in to comment.