Skip to content

Commit

Permalink
tests: runtime: out_splunk: add test for 'Splunk_Send_Raw' (#3337)
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored Apr 20, 2021
1 parent 06a48ce commit 6e9a5cc
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions tests/runtime/out_splunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,76 @@ static void cb_check_basic(void *ctx, int ffd,
char *index_line = "\"event\":{\"key\":\"value\"}";

p = strstr(out_js, index_line);
TEST_CHECK(p != NULL);
if (!TEST_CHECK(p != NULL)) {
TEST_MSG("Given:%s", out_js);
}

flb_sds_destroy(out_js);
}

static void cb_check_send_raw(void *ctx, int ffd,
int res_ret, void *res_data, size_t res_size,
void *data)
{
char *p;
flb_sds_t out_js = res_data;
char *not_match_line = "\"event\":{\"key\":\"value\"}";
char *match_line = "\"key\":\"value\"";

p = strstr(out_js, not_match_line);
if (!TEST_CHECK(p == NULL)) {
TEST_MSG("Given:%s", out_js);
}
p = strstr(out_js, match_line);
if (!TEST_CHECK(p != NULL)) {
TEST_MSG("Given:%s", out_js);
}

flb_sds_destroy(out_js);
}

// Test "Splunk_Send_Raw" property.
void flb_test_send_raw()
{
int ret;
int size = sizeof(JSON_BASIC) - 1;
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;

/* Create context, flush every second (some checks omitted here) */
ctx = flb_create();
flb_service_set(ctx, "flush", "1", "grace", "1", NULL);

/* Lib input mode */
in_ffd = flb_input(ctx, (char *) "lib", NULL);
flb_input_set(ctx, in_ffd, "tag", "test", NULL);

/* Elasticsearch output */
out_ffd = flb_output(ctx, (char *) "splunk", NULL);
flb_output_set(ctx, out_ffd,
"match", "test",
"http_user", "alice",
"splunk_send_raw", "true",
NULL);

/* Enable test mode */
ret = flb_output_set_test(ctx, out_ffd, "formatter",
cb_check_send_raw,
NULL, NULL);

/* Start */
ret = flb_start(ctx);
TEST_CHECK(ret == 0);

/* Ingest data sample */
flb_lib_push(ctx, in_ffd, (char *) JSON_BASIC, size);

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

void flb_test_basic()
{
int ret;
Expand Down Expand Up @@ -79,6 +144,7 @@ void flb_test_basic()

/* Test list */
TEST_LIST = {
{"basic" , flb_test_basic },
{"basic" , flb_test_basic },
{"send_raw" , flb_test_send_raw},
{NULL, NULL}
};

0 comments on commit 6e9a5cc

Please sign in to comment.