Skip to content

Commit

Permalink
tests: runtime: out_es: add test case for long index(fluent#4311)
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 committed Nov 23, 2021
1 parent 766c63f commit 044a2a8
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/runtime/out_elasticsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,80 @@ void flb_test_div0()
flb_destroy(ctx);
}


static void cb_check_long_index(void *ctx, int ffd,
int res_ret, void *res_data, size_t res_size,
void *data)
{
char *p;
char *out_js = res_data;
char long_index[256] = {0};
int i;

for (i=0; i<sizeof(long_index)-1; i++) {
long_index[i] = '0' + (i%10);
}

p = strstr(out_js, &long_index[0]);
TEST_CHECK(p != NULL);
flb_free(res_data);
}

/* https://github.com/fluent/fluent-bit/issues/4311 */
void flb_test_long_index()
{
int ret;
int size = sizeof(JSON_ES) -1;
char long_index[256] = {0};
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;
int i;

for (i=0; i<sizeof(long_index)-1; i++) {
long_index[i] = '0' + (i%10);
}

/* 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",
"generate_id", "true",
"index", &long_index[0],
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_long_index,
NULL, NULL);

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

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

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

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

0 comments on commit 044a2a8

Please sign in to comment.