|
32 | 32 | #define FLB_004 FLB_TESTS_CONF_PATH "/stream_processor.yaml" |
33 | 33 | #define FLB_005 FLB_TESTS_CONF_PATH "/plugins.yaml" |
34 | 34 | #define FLB_006 FLB_TESTS_CONF_PATH "/upstream.yaml" |
| 35 | +#define FLB_008 FLB_TESTS_CONF_PATH "/other_with_nested_map.yaml" |
| 36 | +#define FLB_009 FLB_TESTS_CONF_PATH "/ignorable.yaml" |
35 | 37 |
|
36 | 38 | #define FLB_000_WIN FLB_TESTS_CONF_PATH "\\fluent-bit-windows.yaml" |
37 | 39 | #define FLB_BROKEN_PLUGIN_VARIANT FLB_TESTS_CONF_PATH "/broken_plugin_variant.yaml" |
@@ -364,8 +366,12 @@ static void test_processors() |
364 | 366 | struct cfl_variant *v; |
365 | 367 | struct cfl_variant *logs; |
366 | 368 | struct cfl_variant *record_modifier_filter; |
| 369 | + struct cfl_variant *second_processor; |
367 | 370 | struct cfl_variant *records; |
368 | 371 | struct cfl_variant *record; |
| 372 | + struct cfl_variant *sampling_type; |
| 373 | + struct cfl_variant *sampling_settings; |
| 374 | + struct cfl_variant *sampling_percentage; |
369 | 375 | int idx = 0; |
370 | 376 |
|
371 | 377 | cf = flb_cf_yaml_create(NULL, FLB_002, NULL, 0); |
@@ -432,7 +438,7 @@ static void test_processors() |
432 | 438 |
|
433 | 439 | TEST_CHECK(logs->type == CFL_VARIANT_ARRAY); |
434 | 440 | if (logs->type == CFL_VARIANT_ARRAY) { |
435 | | - TEST_CHECK(logs->data.as_array->entry_count == 1); |
| 441 | + TEST_CHECK(logs->data.as_array->entry_count == 2); |
436 | 442 |
|
437 | 443 | record_modifier_filter = cfl_array_fetch_by_index(logs->data.as_array, 0); |
438 | 444 | TEST_CHECK(record_modifier_filter != NULL); |
@@ -462,6 +468,34 @@ static void test_processors() |
462 | 468 | } |
463 | 469 | } |
464 | 470 | } |
| 471 | + |
| 472 | + second_processor = cfl_array_fetch_by_index(logs->data.as_array, 1); |
| 473 | + TEST_CHECK(second_processor != NULL); |
| 474 | + TEST_CHECK(second_processor->type == CFL_VARIANT_KVLIST); |
| 475 | + |
| 476 | + if (second_processor != NULL && second_processor->type == CFL_VARIANT_KVLIST) { |
| 477 | + sampling_type = cfl_kvlist_fetch(second_processor->data.as_kvlist, "type"); |
| 478 | + TEST_CHECK(sampling_type != NULL); |
| 479 | + TEST_CHECK(sampling_type->type == CFL_VARIANT_STRING); |
| 480 | + TEST_CHECK(strcmp(sampling_type->data.as_string, "probabilistic") == 0); |
| 481 | + |
| 482 | + sampling_settings = cfl_kvlist_fetch(second_processor->data.as_kvlist, |
| 483 | + "sampling_settings"); |
| 484 | + TEST_CHECK(sampling_settings != NULL); |
| 485 | + TEST_CHECK(sampling_settings->type == CFL_VARIANT_KVLIST); |
| 486 | + |
| 487 | + if (sampling_settings != NULL && |
| 488 | + sampling_settings->type == CFL_VARIANT_KVLIST) { |
| 489 | + sampling_percentage = cfl_kvlist_fetch(sampling_settings->data.as_kvlist, |
| 490 | + "sampling_percentage"); |
| 491 | + TEST_CHECK(sampling_percentage != NULL); |
| 492 | + TEST_CHECK(sampling_percentage->type == CFL_VARIANT_UINT); |
| 493 | + if (sampling_percentage != NULL && |
| 494 | + sampling_percentage->type == CFL_VARIANT_UINT) { |
| 495 | + TEST_CHECK(sampling_percentage->data.as_uint64 == 25); |
| 496 | + } |
| 497 | + } |
| 498 | + } |
465 | 499 | } |
466 | 500 | } |
467 | 501 |
|
@@ -835,6 +869,51 @@ static void test_upstream_servers() |
835 | 869 | flb_cf_destroy(cf); |
836 | 870 | } |
837 | 871 |
|
| 872 | +static void test_ignorable_section() |
| 873 | +{ |
| 874 | + struct flb_cf *cf; |
| 875 | + struct flb_cf_section *s; |
| 876 | + struct cfl_variant *v; |
| 877 | + struct cfl_variant *nested; |
| 878 | + |
| 879 | + cf = flb_cf_yaml_create(NULL, FLB_009, NULL, 0); |
| 880 | + TEST_CHECK(cf != NULL); |
| 881 | + if (!cf) { |
| 882 | + exit(EXIT_FAILURE); |
| 883 | + } |
| 884 | + |
| 885 | + s = flb_cf_section_get_by_name(cf, "ignorable"); |
| 886 | + TEST_CHECK(s != NULL); |
| 887 | + |
| 888 | + v = flb_cf_section_property_get(cf, s, "record_metadata"); |
| 889 | + TEST_CHECK(v != NULL); |
| 890 | + TEST_CHECK(v->type == CFL_VARIANT_KVLIST); |
| 891 | + |
| 892 | + if (v != NULL && v->type == CFL_VARIANT_KVLIST) { |
| 893 | + nested = cfl_kvlist_fetch(v->data.as_kvlist, "enabled"); |
| 894 | + TEST_CHECK(nested != NULL); |
| 895 | + TEST_CHECK(nested->type == CFL_VARIANT_BOOL); |
| 896 | + TEST_CHECK(nested->data.as_bool == CFL_TRUE); |
| 897 | + } |
| 898 | + |
| 899 | + v = flb_cf_section_property_get(cf, s, "otlp"); |
| 900 | + TEST_CHECK(v != NULL); |
| 901 | + TEST_CHECK(v->type == CFL_VARIANT_KVLIST); |
| 902 | + |
| 903 | + flb_cf_destroy(cf); |
| 904 | +} |
| 905 | + |
| 906 | +static void test_other_nested_map_rejected() |
| 907 | +{ |
| 908 | + struct flb_cf *cf; |
| 909 | + |
| 910 | + cf = flb_cf_yaml_create(NULL, FLB_008, NULL, 0); |
| 911 | + TEST_CHECK(cf == NULL); |
| 912 | + if (cf != NULL) { |
| 913 | + flb_cf_destroy(cf); |
| 914 | + } |
| 915 | +} |
| 916 | + |
838 | 917 | static void test_invalid_property() |
839 | 918 | { |
840 | 919 | char* test_cases[] = { |
@@ -876,6 +955,8 @@ TEST_LIST = { |
876 | 955 | { "stream_processor", test_stream_processor}, |
877 | 956 | { "plugins", test_plugins}, |
878 | 957 | { "upstream_servers", test_upstream_servers}, |
| 958 | + { "ignorable_section", test_ignorable_section}, |
| 959 | + { "other_nested_map_rejected", test_other_nested_map_rejected}, |
879 | 960 | { "invalid_input_property", test_invalid_property}, |
880 | 961 | { 0 } |
881 | 962 | }; |
0 commit comments