|
1 | 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | 2 |
|
| 3 | +#include <monkey/mk_core/mk_list.h> |
3 | 4 | #include <fluent-bit.h> |
4 | 5 | #include "flb_tests_runtime.h" |
5 | 6 |
|
6 | 7 | /* Test data */ |
7 | 8 | #include "data/es/json_es.h" /* JSON_ES */ |
8 | 9 |
|
| 10 | +/* |
| 11 | + * Include plugin headers to get the definition of structure used as flush context |
| 12 | + * and to know how to extract that structure from plugin context. |
| 13 | + */ |
| 14 | +#include "../../plugins/out_es/es.h" |
| 15 | +#include "../../plugins/out_es/es_conf.h" |
| 16 | + |
| 17 | +static void *cb_flush_context(struct flb_config *config, struct flb_input_instance *ins, |
| 18 | + void *plugin_context, void *flush_ctx) |
| 19 | +{ |
| 20 | + struct flb_elasticsearch *ctx = plugin_context; |
| 21 | + (void) config; |
| 22 | + (void) ins; |
| 23 | + (void) flush_ctx; |
| 24 | + return flb_es_upstream_conf(ctx, NULL); |
| 25 | +} |
9 | 26 |
|
10 | 27 | static void cb_check_write_op_index(void *ctx, int ffd, |
11 | 28 | int res_ret, void *res_data, |
@@ -195,9 +212,10 @@ void flb_test_write_operation_index() |
195 | 212 | NULL); |
196 | 213 |
|
197 | 214 | /* Enable test mode */ |
198 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
199 | | - cb_check_write_op_index, |
200 | | - NULL, NULL); |
| 215 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 216 | + cb_check_write_op_index, |
| 217 | + NULL, NULL, cb_flush_context); |
| 218 | + TEST_CHECK(ret == 0); |
201 | 219 |
|
202 | 220 | /* Start */ |
203 | 221 | ret = flb_start(ctx); |
@@ -239,9 +257,10 @@ void flb_test_write_operation_create() |
239 | 257 | NULL); |
240 | 258 |
|
241 | 259 | /* Enable test mode */ |
242 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
243 | | - cb_check_write_op_create, |
244 | | - NULL, NULL); |
| 260 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 261 | + cb_check_write_op_create, |
| 262 | + NULL, NULL, cb_flush_context); |
| 263 | + TEST_CHECK(ret == 0); |
245 | 264 |
|
246 | 265 | /* Start */ |
247 | 266 | ret = flb_start(ctx); |
@@ -285,9 +304,10 @@ void flb_test_write_operation_update() |
285 | 304 | NULL); |
286 | 305 |
|
287 | 306 | /* Enable test mode */ |
288 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
289 | | - cb_check_write_op_update, |
290 | | - NULL, NULL); |
| 307 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 308 | + cb_check_write_op_update, |
| 309 | + NULL, NULL, cb_flush_context); |
| 310 | + TEST_CHECK(ret == 0); |
291 | 311 |
|
292 | 312 | /* Start */ |
293 | 313 | ret = flb_start(ctx); |
@@ -331,9 +351,10 @@ void flb_test_write_operation_upsert() |
331 | 351 | NULL); |
332 | 352 |
|
333 | 353 | /* Enable test mode */ |
334 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
335 | | - cb_check_write_op_upsert, |
336 | | - NULL, NULL); |
| 354 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 355 | + cb_check_write_op_upsert, |
| 356 | + NULL, NULL, cb_flush_context); |
| 357 | + TEST_CHECK(ret == 0); |
337 | 358 |
|
338 | 359 | /* Start */ |
339 | 360 | ret = flb_start(ctx); |
@@ -376,9 +397,10 @@ void flb_test_index_type() |
376 | 397 | NULL); |
377 | 398 |
|
378 | 399 | /* Enable test mode */ |
379 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
380 | | - cb_check_index_type, |
381 | | - NULL, NULL); |
| 400 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 401 | + cb_check_index_type, |
| 402 | + NULL, NULL, cb_flush_context); |
| 403 | + TEST_CHECK(ret == 0); |
382 | 404 |
|
383 | 405 | /* Start */ |
384 | 406 | ret = flb_start(ctx); |
@@ -422,9 +444,10 @@ void flb_test_logstash_format() |
422 | 444 | NULL); |
423 | 445 |
|
424 | 446 | /* Enable test mode */ |
425 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
426 | | - cb_check_logstash_format, |
427 | | - NULL, NULL); |
| 447 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 448 | + cb_check_logstash_format, |
| 449 | + NULL, NULL, cb_flush_context); |
| 450 | + TEST_CHECK(ret == 0); |
428 | 451 |
|
429 | 452 | /* Start */ |
430 | 453 | ret = flb_start(ctx); |
@@ -469,9 +492,10 @@ void flb_test_logstash_format_nanos() |
469 | 492 | NULL); |
470 | 493 |
|
471 | 494 | /* Enable test mode */ |
472 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
473 | | - cb_check_logstash_format_nanos, |
474 | | - NULL, NULL); |
| 495 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 496 | + cb_check_logstash_format_nanos, |
| 497 | + NULL, NULL, cb_flush_context); |
| 498 | + TEST_CHECK(ret == 0); |
475 | 499 |
|
476 | 500 | /* Start */ |
477 | 501 | ret = flb_start(ctx); |
@@ -514,9 +538,10 @@ void flb_test_tag_key() |
514 | 538 | NULL); |
515 | 539 |
|
516 | 540 | /* Enable test mode */ |
517 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
518 | | - cb_check_tag_key, |
519 | | - NULL, NULL); |
| 541 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 542 | + cb_check_tag_key, |
| 543 | + NULL, NULL, cb_flush_context); |
| 544 | + TEST_CHECK(ret == 0); |
520 | 545 |
|
521 | 546 | /* Start */ |
522 | 547 | ret = flb_start(ctx); |
@@ -558,9 +583,10 @@ void flb_test_replace_dots() |
558 | 583 | NULL); |
559 | 584 |
|
560 | 585 | /* Enable test mode */ |
561 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
562 | | - cb_check_replace_dots, |
563 | | - NULL, NULL); |
| 586 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 587 | + cb_check_replace_dots, |
| 588 | + NULL, NULL, cb_flush_context); |
| 589 | + TEST_CHECK(ret == 0); |
564 | 590 |
|
565 | 591 | /* Start */ |
566 | 592 | ret = flb_start(ctx); |
@@ -602,9 +628,10 @@ void flb_test_id_key() |
602 | 628 | NULL); |
603 | 629 |
|
604 | 630 | /* Enable test mode */ |
605 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
606 | | - cb_check_id_key, |
607 | | - NULL, NULL); |
| 631 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 632 | + cb_check_id_key, |
| 633 | + NULL, NULL, cb_flush_context); |
| 634 | + TEST_CHECK(ret == 0); |
608 | 635 |
|
609 | 636 | /* Start */ |
610 | 637 | ret = flb_start(ctx); |
@@ -656,9 +683,10 @@ void flb_test_div0() |
656 | 683 | NULL); |
657 | 684 |
|
658 | 685 | /* Enable test mode */ |
659 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
660 | | - cb_check_nothing, |
661 | | - NULL, NULL); |
| 686 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 687 | + cb_check_nothing, |
| 688 | + NULL, NULL, cb_flush_context); |
| 689 | + TEST_CHECK(ret == 0); |
662 | 690 |
|
663 | 691 | /* Start */ |
664 | 692 | ret = flb_start(ctx); |
@@ -736,9 +764,10 @@ void flb_test_long_index() |
736 | 764 | NULL); |
737 | 765 |
|
738 | 766 | /* Enable test mode */ |
739 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
740 | | - cb_check_long_index, |
741 | | - NULL, NULL); |
| 767 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 768 | + cb_check_long_index, |
| 769 | + NULL, NULL, cb_flush_context); |
| 770 | + TEST_CHECK(ret == 0); |
742 | 771 |
|
743 | 772 | /* Start */ |
744 | 773 | ret = flb_start(ctx); |
@@ -783,9 +812,10 @@ void flb_test_logstash_prefix_separator() |
783 | 812 | NULL); |
784 | 813 |
|
785 | 814 | /* Enable test mode */ |
786 | | - ret = flb_output_set_test(ctx, out_ffd, "formatter", |
787 | | - cb_check_logstash_prefix_separator, |
788 | | - NULL, NULL); |
| 815 | + ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter", |
| 816 | + cb_check_logstash_prefix_separator, |
| 817 | + NULL, NULL, cb_flush_context); |
| 818 | + TEST_CHECK(ret == 0); |
789 | 819 |
|
790 | 820 | /* Start */ |
791 | 821 | ret = flb_start(ctx); |
|
0 commit comments