Skip to content

Commit f97cead

Browse files
committed
tests: config_format_yaml: Add test cases for annotations
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent a6f14ae commit f97cead

4 files changed

Lines changed: 102 additions & 1 deletion

File tree

tests/internal/config_format_yaml.c

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define FLB_004 FLB_TESTS_CONF_PATH "/stream_processor.yaml"
3333
#define FLB_005 FLB_TESTS_CONF_PATH "/plugins.yaml"
3434
#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"
3537

3638
#define FLB_000_WIN FLB_TESTS_CONF_PATH "\\fluent-bit-windows.yaml"
3739
#define FLB_BROKEN_PLUGIN_VARIANT FLB_TESTS_CONF_PATH "/broken_plugin_variant.yaml"
@@ -364,8 +366,12 @@ static void test_processors()
364366
struct cfl_variant *v;
365367
struct cfl_variant *logs;
366368
struct cfl_variant *record_modifier_filter;
369+
struct cfl_variant *second_processor;
367370
struct cfl_variant *records;
368371
struct cfl_variant *record;
372+
struct cfl_variant *sampling_type;
373+
struct cfl_variant *sampling_settings;
374+
struct cfl_variant *sampling_percentage;
369375
int idx = 0;
370376

371377
cf = flb_cf_yaml_create(NULL, FLB_002, NULL, 0);
@@ -432,7 +438,7 @@ static void test_processors()
432438

433439
TEST_CHECK(logs->type == CFL_VARIANT_ARRAY);
434440
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);
436442

437443
record_modifier_filter = cfl_array_fetch_by_index(logs->data.as_array, 0);
438444
TEST_CHECK(record_modifier_filter != NULL);
@@ -462,6 +468,34 @@ static void test_processors()
462468
}
463469
}
464470
}
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+
}
465499
}
466500
}
467501

@@ -835,6 +869,51 @@ static void test_upstream_servers()
835869
flb_cf_destroy(cf);
836870
}
837871

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+
838917
static void test_invalid_property()
839918
{
840919
char* test_cases[] = {
@@ -876,6 +955,8 @@ TEST_LIST = {
876955
{ "stream_processor", test_stream_processor},
877956
{ "plugins", test_plugins},
878957
{ "upstream_servers", test_upstream_servers},
958+
{ "ignorable_section", test_ignorable_section},
959+
{ "other_nested_map_rejected", test_other_nested_map_rejected},
879960
{ "invalid_input_property", test_invalid_property},
880961
{ 0 }
881962
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
service:
2+
flush: 1
3+
log_level: info
4+
5+
ignorable:
6+
recordMetadata:
7+
enabled: true
8+
otlp:
9+
endpoint: 127.0.0.1:4318
10+
insecure: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
service:
2+
flush: 1
3+
4+
custom_info:
5+
nested:
6+
key: value

tests/internal/data/config_format/yaml/processors.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ pipeline:
88
record:
99
- filtered_by record_modifier
1010
- powered_by calyptia
11+
- name: sampling
12+
type: probabilistic
13+
sampling_settings:
14+
sampling_percentage: 25
1115
outputs:
1216
- name: stdout
1317
match: "*"

0 commit comments

Comments
 (0)