|
7 | 7 | #include "data/es/json_es.h" /* JSON_ES */ |
8 | 8 |
|
9 | 9 |
|
| 10 | +static void cb_check_http_api_key(void *ctx, int ffd, |
| 11 | + int res_ret, void *res_data, |
| 12 | + size_t res_size, void *data) |
| 13 | +{ |
| 14 | + char *api_key = data; |
| 15 | + |
| 16 | + TEST_CHECK(api_key != NULL); |
| 17 | + TEST_CHECK(strlen(api_key) > 0); |
| 18 | + |
| 19 | + TEST_CHECK(strcmp(api_key, "my-api-key-for-elasticsearch") == 0); |
| 20 | + |
| 21 | + flb_free(res_data); |
| 22 | +} |
| 23 | + |
| 24 | + |
10 | 25 | static void cb_check_write_op_index(void *ctx, int ffd, |
11 | 26 | int res_ret, void *res_data, |
12 | 27 | size_t res_size, void *data) |
@@ -722,6 +737,51 @@ void flb_test_div0() |
722 | 737 | flb_destroy(ctx); |
723 | 738 | } |
724 | 739 |
|
| 740 | +void flb_test_http_api_key() |
| 741 | +{ |
| 742 | + int ret; |
| 743 | + int size = sizeof(JSON_ES) - 1; |
| 744 | + flb_ctx_t *ctx; |
| 745 | + int in_ffd; |
| 746 | + int out_ffd; |
| 747 | + char *api_key = "my-api-key-for-elasticsearch"; |
| 748 | + |
| 749 | + /* Create context, flush every second (some checks omitted here) */ |
| 750 | + ctx = flb_create(); |
| 751 | + flb_service_set(ctx, "flush", "1", "grace", "1", NULL); |
| 752 | + |
| 753 | + /* Lib input mode */ |
| 754 | + in_ffd = flb_input(ctx, (char *) "lib", NULL); |
| 755 | + flb_input_set(ctx, in_ffd, "tag", "test", NULL); |
| 756 | + |
| 757 | + /* Elasticsearch output */ |
| 758 | + out_ffd = flb_output(ctx, (char *) "es", NULL); |
| 759 | + flb_output_set(ctx, out_ffd, |
| 760 | + "match", "test", |
| 761 | + NULL); |
| 762 | + |
| 763 | + /* Configure http_api_key */ |
| 764 | + flb_output_set(ctx, out_ffd, |
| 765 | + "http_api_key", api_key, |
| 766 | + NULL); |
| 767 | + |
| 768 | + /* Enable test mode */ |
| 769 | + ret = flb_output_set_test(ctx, out_ffd, "formatter", |
| 770 | + cb_check_http_api_key, |
| 771 | + api_key, NULL); |
| 772 | + |
| 773 | + /* Start */ |
| 774 | + ret = flb_start(ctx); |
| 775 | + TEST_CHECK(ret == 0); |
| 776 | + |
| 777 | + /* Ingest data sample */ |
| 778 | + flb_lib_push(ctx, in_ffd, (char *) JSON_ES, size); |
| 779 | + |
| 780 | + sleep(2); |
| 781 | + flb_stop(ctx); |
| 782 | + flb_destroy(ctx); |
| 783 | +} |
| 784 | + |
725 | 785 |
|
726 | 786 | static void cb_check_long_index(void *ctx, int ffd, |
727 | 787 | int res_ret, void *res_data, size_t res_size, |
@@ -1012,6 +1072,7 @@ TEST_LIST = { |
1012 | 1072 | {"tag_key" , flb_test_tag_key }, |
1013 | 1073 | {"replace_dots" , flb_test_replace_dots }, |
1014 | 1074 | {"id_key" , flb_test_id_key }, |
| 1075 | + {"http_api_key" , flb_test_http_api_key }, |
1015 | 1076 | {"logstash_prefix_separator" , flb_test_logstash_prefix_separator }, |
1016 | 1077 | {"response_success" , flb_test_response_success }, |
1017 | 1078 | {"response_successes", flb_test_response_successes }, |
|
0 commit comments