Skip to content

Commit

Permalink
tests: config_format: yaml: test input processors in yaml configuration.
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan committed Oct 12, 2023
1 parent 5d909df commit 6a95c59
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 3 deletions.
122 changes: 119 additions & 3 deletions tests/internal/config_format_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define FLB_TESTS_CONF_PATH FLB_TESTS_DATA_PATH "/data/config_format/yaml"
#define FLB_000 FLB_TESTS_CONF_PATH "/fluent-bit.yaml"
#define FLB_001 FLB_TESTS_CONF_PATH "/issue_7559.yaml"
#define FLB_002 FLB_TESTS_CONF_PATH "/processors.yaml"

/*
* Configurations to test:
Expand Down Expand Up @@ -47,7 +48,7 @@ static void test_basic()
/* Total number of sections */
TEST_CHECK(mk_list_size(&cf->sections) == 9);

/* SERVICE check */
/* SERVICE check */
TEST_CHECK(cf->service != NULL);
if (cf->service) {
TEST_CHECK(cfl_list_size(&cf->service->properties->list) == 3);
Expand Down Expand Up @@ -262,8 +263,8 @@ static void test_parser_conf()
/* Total number of inputs */
if(!TEST_CHECK(mk_list_size(&config->parsers) == cnt+1)) {
TEST_MSG("Section number error. Got=%d expect=%d",
mk_list_size(&config->parsers),
cnt+1);
mk_list_size(&config->parsers),
cnt+1);
}

flb_cf_dump(cf);
Expand Down Expand Up @@ -313,12 +314,127 @@ static void test_camel_case_key()

}

/* data/config_format/processors.yaml */
static void test_processors()
{
struct mk_list *head;
struct flb_cf *cf;
struct flb_cf_section *s;
struct flb_cf_group *g;
struct cfl_variant *v;
struct cfl_variant *logs;
struct cfl_variant *record_modifier_filter;
struct cfl_variant *records;
struct cfl_variant *record;
int idx = 0;

cf = flb_cf_yaml_create(NULL, FLB_002, NULL, 0);
TEST_CHECK(cf != NULL);
if (!cf) {
exit(EXIT_FAILURE);
}

/* Total number of sections */
TEST_CHECK(mk_list_size(&cf->sections) == 2);

/* Check number sections per list */
TEST_CHECK(mk_list_size(&cf->parsers) == 0);
TEST_CHECK(mk_list_size(&cf->multiline_parsers) == 0);
TEST_CHECK(mk_list_size(&cf->customs) == 0);
TEST_CHECK(mk_list_size(&cf->inputs) == 1);
TEST_CHECK(mk_list_size(&cf->filters) == 0);
TEST_CHECK(mk_list_size(&cf->outputs) == 1);
TEST_CHECK(mk_list_size(&cf->others) == 0);

/* check inputs */
idx = 0;
mk_list_foreach(head, &cf->inputs) {
s = mk_list_entry(head, struct flb_cf_section, _head_section);
switch (idx) {
case 0:
v = flb_cf_section_property_get(cf, s, "name");
TEST_CHECK(v->type == CFL_VARIANT_STRING);
TEST_CHECK(strcmp(v->data.as_string, "dummy") == 0);
break;
}
idx++;
}

/* check outputs */
idx = 0;
mk_list_foreach(head, &cf->outputs) {
s = mk_list_entry(head, struct flb_cf_section, _head_section);
switch (idx) {
case 0:
v = flb_cf_section_property_get(cf, s, "name");
TEST_CHECK(v->type == CFL_VARIANT_STRING);
TEST_CHECK(strcmp(v->data.as_string, "stdout") == 0);
break;
}
idx++;
}

/* groups */
s = flb_cf_section_get_by_name(cf, "input");
TEST_CHECK(s != NULL);
TEST_CHECK(mk_list_size(&s->groups) == 1);

mk_list_foreach(head, &s->groups) {
g = mk_list_entry(head, struct flb_cf_group, _head);
TEST_CHECK(cfl_list_size(&g->properties->list) == 1);
TEST_CHECK(strcmp(g->name, "processors") == 0);

logs = cfl_kvlist_fetch(g->properties, "logs");
TEST_CHECK(logs != NULL);
if (logs == NULL) {
continue;
}

TEST_CHECK(logs->type == CFL_VARIANT_ARRAY);
if (logs->type == CFL_VARIANT_ARRAY) {
TEST_CHECK(logs->data.as_array->entry_count == 1);

record_modifier_filter = cfl_array_fetch_by_index(logs->data.as_array, 0);
TEST_CHECK(record_modifier_filter != NULL);

if (record_modifier_filter) {
TEST_CHECK(record_modifier_filter->type == CFL_VARIANT_KVLIST);

records = cfl_kvlist_fetch(record_modifier_filter->data.as_kvlist, "record");
TEST_CHECK(records->type == CFL_VARIANT_ARRAY);
TEST_CHECK(records->data.as_array->entry_count == 2);

for (idx = 0; idx < 2; idx++) {
record = cfl_array_fetch_by_index(records->data.as_array, idx);
TEST_CHECK(record->type == CFL_VARIANT_STRING);

if (record->type != CFL_VARIANT_STRING) {
continue;
}

switch (idx) {
case 0:
TEST_CHECK(strcmp(record->data.as_string, "filtered_by record_modifier") == 0);
break;
case 1:
TEST_CHECK(strcmp(record->data.as_string, "powered_by calyptia") == 0);
break;
}
}
}
}
}

flb_cf_destroy(cf);
}

TEST_LIST = {
{ "basic" , test_basic},
{ "customs section", test_customs_section},
{ "slist odd", test_slist_odd},
{ "slist even", test_slist_even},
{ "parsers file conf", test_parser_conf},
{ "camel_case_key", test_camel_case_key},
{ "processors", test_processors},
{ 0 }
};
14 changes: 14 additions & 0 deletions tests/internal/data/config_format/yaml/processors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
pipeline:
inputs:
- name: dummy
processors:
logs:
- name: record_modifier
record:
- filtered_by record_modifier
- powered_by calyptia
outputs:
- name: stdout
match: "*"
format: json_lines

0 comments on commit 6a95c59

Please sign in to comment.