Skip to content

Commit f854deb

Browse files
committed
engine: support of tests which require generation of context passed to the test callback based on configuration of Fluent Bit and based on configuration of plugin
Signed-off-by: Marat Abrarov <[email protected]>
1 parent a6a3289 commit f854deb

File tree

3 files changed

+160
-85
lines changed

3 files changed

+160
-85
lines changed

include/fluent-bit/flb_lib.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,14 @@ FLB_EXPORT int flb_output_set_test(flb_ctx_t *ctx, int ffd, char *test_name,
7070
void (*out_callback) (void *, int, int,
7171
void *, size_t, void *),
7272
void *out_callback_data,
73-
void *test_ctx);
74-
FLB_EXPORT int flb_output_set_test_with_ctx_callback(
75-
flb_ctx_t *ctx, int ffd, char *test_name,
76-
void (*out_callback) (void *, int, int,
77-
void *, size_t, void *),
78-
void *out_callback_data,
79-
void *test_ctx,
80-
void *(*test_ctx_callback) (
81-
struct flb_config *,
82-
struct flb_input_instance *,
83-
void *, void *));
73+
void *flush_ctx);
74+
FLB_EXPORT int flb_output_set_test_flush_ctx_callback(flb_ctx_t *ctx, int ffd,
75+
char *test_name,
76+
void *(*flush_ctx_callback)(
77+
struct flb_config *,
78+
struct flb_input_instance *,
79+
void *, void *),
80+
void *flush_ctx);
8481
FLB_EXPORT int flb_output_set_callback(flb_ctx_t *ctx, int ffd, char *name,
8582
void (*cb)(char *, void *, void *));
8683
FLB_EXPORT int flb_output_set_http_test(flb_ctx_t *ctx, int ffd, char *test_name,

src/flb_lib.c

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -579,19 +579,42 @@ int flb_output_set_callback(flb_ctx_t *ctx, int ffd, char *name,
579579
int flb_output_set_test(flb_ctx_t *ctx, int ffd, char *test_name,
580580
void (*out_callback) (void *, int, int, void *, size_t, void *),
581581
void *out_callback_data,
582-
void *test_ctx)
582+
void *flush_ctx)
583583
{
584-
return flb_output_set_test_with_ctx_callback(ctx, ffd, test_name, out_callback,
585-
out_callback_data, test_ctx, NULL);
584+
struct flb_output_instance *o_ins;
585+
586+
o_ins = out_instance_get(ctx, ffd);
587+
if (!o_ins) {
588+
return -1;
589+
}
590+
591+
/*
592+
* Enabling a test, set the output instance in 'test' mode, so no real
593+
* flush callback is invoked, only the desired implemented test.
594+
*/
595+
596+
/* Formatter test */
597+
if (strcmp(test_name, "formatter") == 0) {
598+
o_ins->test_mode = FLB_TRUE;
599+
o_ins->test_formatter.rt_ctx = ctx;
600+
o_ins->test_formatter.rt_ffd = ffd;
601+
o_ins->test_formatter.rt_out_callback = out_callback;
602+
o_ins->test_formatter.rt_data = out_callback_data;
603+
o_ins->test_formatter.flush_ctx = flush_ctx;
604+
}
605+
else {
606+
return -1;
607+
}
608+
609+
return 0;
586610
}
587611

588-
int flb_output_set_test_with_ctx_callback(flb_ctx_t *ctx, int ffd, char *test_name,
589-
void (*out_callback) (void *, int, int, void *, size_t, void *),
590-
void *out_callback_data,
591-
void *test_ctx,
592-
void *(*test_ctx_callback) (struct flb_config *,
593-
struct flb_input_instance *,
594-
void *, void *))
612+
int flb_output_set_test_flush_ctx_callback(flb_ctx_t *ctx, int ffd,
613+
char *test_name,
614+
void *(*flush_ctx_callback) (struct flb_config *,
615+
struct flb_input_instance *,
616+
void *, void *),
617+
void *flush_ctx)
595618
{
596619
struct flb_output_instance *o_ins;
597620

@@ -610,10 +633,8 @@ int flb_output_set_test_with_ctx_callback(flb_ctx_t *ctx, int ffd, char *test_na
610633
o_ins->test_mode = FLB_TRUE;
611634
o_ins->test_formatter.rt_ctx = ctx;
612635
o_ins->test_formatter.rt_ffd = ffd;
613-
o_ins->test_formatter.rt_out_callback = out_callback;
614-
o_ins->test_formatter.rt_data = out_callback_data;
615-
o_ins->test_formatter.flush_ctx = test_ctx;
616-
o_ins->test_formatter.flush_ctx_callback = test_ctx_callback;
636+
o_ins->test_formatter.flush_ctx = flush_ctx;
637+
o_ins->test_formatter.flush_ctx_callback = flush_ctx_callback;
617638
}
618639
else {
619640
return -1;

0 commit comments

Comments
 (0)