Skip to content

Commit

Permalink
tests: runtime: out_es: add testcase for div0
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Aug 13, 2021
1 parent fb628e7 commit febfb9e
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion tests/runtime/out_elasticsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void flb_test_replace_dots()
void flb_test_id_key()
{
int ret;
int size = sizeof(JSON_DOTS) - 1;
int size = sizeof(JSON_ES) - 1;
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;
Expand Down Expand Up @@ -357,8 +357,74 @@ void flb_test_id_key()
flb_destroy(ctx);
}

/* no check */
static void cb_check_nothing(void *ctx, int ffd,
int res_ret, void *res_data, size_t res_size,
void *data)
{
char *p;
char *out_js = res_data;
flb_free(res_data);
}

/* https://github.com/fluent/fluent-bit/issues/3905 */
void flb_test_div0()
{
int ret;
char record[8000];
char record_header[] = "[1448403340,{\"key\":\"";
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;
int i;

/* 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 *) "es", NULL);
flb_output_set(ctx, out_ffd,
"match", "test",
NULL);

/* Override defaults of index and type */
flb_output_set(ctx, out_ffd,
NULL);

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

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

/* create json */
strncpy(&record[0], &record_header[0], strlen(record_header));
for(i=strlen(record_header); i<sizeof(record)-4; i++) {
record[i] = 'a';
}
record[sizeof(record)-4] = '"';
record[sizeof(record)-3] = '}';
record[sizeof(record)-2] = ']';
record[sizeof(record)-1] = '\0';
/* Ingest data sample */
flb_lib_push(ctx, in_ffd, (char *) &record[0], strlen(record));

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

/* Test list */
TEST_LIST = {
{"div0_error" , flb_test_div0 },
{"index_type" , flb_test_index_type },
{"logstash_format" , flb_test_logstash_format },
{"logstash_format_nanos", flb_test_logstash_format_nanos },
Expand Down

0 comments on commit febfb9e

Please sign in to comment.