Skip to content

Commit

Permalink
tests: internal: log_event_encoder: add test for issue 8137
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 committed Feb 4, 2024
1 parent 978b280 commit 7e06f51
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion tests/internal/log_event_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ static int compare_msgpack_format_fluentbit_v2(void *msgpack_data, size_t msgpac
msgpack_unpacked_destroy(&result);
return -1;
}

}
msgpack_unpacked_destroy(&result);

Expand Down Expand Up @@ -650,6 +649,78 @@ static void emit_raw_record()
flb_log_event_encoder_destroy(&encoder);
}

static void issue_8137_calc_len()
{
struct flb_log_event_encoder encoder;
int ret;
char *prefix = "_map_data.";
size_t prefix_len = strlen(prefix);
char *val = "key";
size_t val_len = strlen(val);
msgpack_unpacked result;
size_t off = 0;

ret = flb_log_event_encoder_init(&encoder, FLB_LOG_EVENT_FORMAT_FLUENT_BIT_V2);
if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) {
TEST_MSG("flb_log_event_encoder_init failed");
return;
}

ret = flb_log_event_encoder_begin_record(&encoder);
if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) {
TEST_MSG("flb_log_event_encoder_begin_record failed. ret=%s",
flb_log_event_encoder_get_error_description(ret));
flb_log_event_encoder_destroy(&encoder);
return;
}

ret = flb_log_event_encoder_set_current_timestamp(&encoder);
if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) {
TEST_MSG("flb_log_event_encoder_set_current_timestamp failed. ret=%s",
flb_log_event_encoder_get_error_description(ret));
flb_log_event_encoder_destroy(&encoder);
return;
}

ret = flb_log_event_encoder_append_body_values(
&encoder,
FLB_LOG_EVENT_STRING_LENGTH_VALUE(prefix_len+val_len),
FLB_LOG_EVENT_STRING_BODY_VALUE(prefix, prefix_len),
FLB_LOG_EVENT_STRING_BODY_VALUE(val, val_len)
);


if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) {
TEST_MSG("flb_log_event_encoder_append_body_values failed. ret=%s",
flb_log_event_encoder_get_error_description(ret));
flb_log_event_encoder_destroy(&encoder);
return;
}

ret = flb_log_event_encoder_commit_record(&encoder);
if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) {
TEST_MSG("flb_log_event_encoder_commit_record failed. ret=%s",
flb_log_event_encoder_get_error_description(ret));
flb_log_event_encoder_destroy(&encoder);
return;
}

msgpack_unpacked_init(&result);
msgpack_unpack_next(&result, encoder.output_buffer, encoder.output_length, &off);

if (!TEST_CHECK(result.data.type != MSGPACK_OBJECT_STR)) {
TEST_MSG("data is not string");
}
else if (!TEST_CHECK(result.data.via.str.size != prefix_len + val_len)) {
TEST_MSG("size mismatch. got=%u expect=%ld", result.data.via.str.size,
prefix_len + val_len);
}


msgpack_unpacked_destroy(&result);
flb_log_event_encoder_destroy(&encoder);
}

TEST_LIST = {
{ "basic_format_fluent_bit_v2", basic_format_fluent_bit_v2},
{ "basic_format_fluent_bit_v1", basic_format_fluent_bit_v1},
Expand All @@ -659,5 +730,6 @@ TEST_LIST = {
{ "init_destroy", init_destroy},
{ "init_unsupported_format", init_unsupported_format},
{ "emit_raw_record", emit_raw_record},
{ "issue_8137_calc_len", issue_8137_calc_len},
{ NULL, NULL }
};

0 comments on commit 7e06f51

Please sign in to comment.