Skip to content

Commit a095d9e

Browse files
pwhelanedsiper
authored andcommitted
tests: config_format: yaml: test input processors in yaml configuration.
Signed-off-by: Phillip Whelan <[email protected]>
1 parent 6a1c62d commit a095d9e

File tree

2 files changed

+133
-3
lines changed

2 files changed

+133
-3
lines changed

tests/internal/config_format_yaml.c

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define FLB_TESTS_CONF_PATH FLB_TESTS_DATA_PATH "/data/config_format/yaml"
1515
#define FLB_000 FLB_TESTS_CONF_PATH "/fluent-bit.yaml"
1616
#define FLB_001 FLB_TESTS_CONF_PATH "/issue_7559.yaml"
17+
#define FLB_002 FLB_TESTS_CONF_PATH "/processors.yaml"
1718

1819
/*
1920
* Configurations to test:
@@ -47,7 +48,7 @@ static void test_basic()
4748
/* Total number of sections */
4849
TEST_CHECK(mk_list_size(&cf->sections) == 9);
4950

50-
/* SERVICE check */
51+
/* SERVICE check */
5152
TEST_CHECK(cf->service != NULL);
5253
if (cf->service) {
5354
TEST_CHECK(cfl_list_size(&cf->service->properties->list) == 3);
@@ -262,8 +263,8 @@ static void test_parser_conf()
262263
/* Total number of inputs */
263264
if(!TEST_CHECK(mk_list_size(&config->parsers) == cnt+1)) {
264265
TEST_MSG("Section number error. Got=%d expect=%d",
265-
mk_list_size(&config->parsers),
266-
cnt+1);
266+
mk_list_size(&config->parsers),
267+
cnt+1);
267268
}
268269

269270
flb_cf_dump(cf);
@@ -313,12 +314,127 @@ static void test_camel_case_key()
313314

314315
}
315316

317+
/* data/config_format/processors.yaml */
318+
static void test_processors()
319+
{
320+
struct mk_list *head;
321+
struct flb_cf *cf;
322+
struct flb_cf_section *s;
323+
struct flb_cf_group *g;
324+
struct cfl_variant *v;
325+
struct cfl_variant *logs;
326+
struct cfl_variant *record_modifier_filter;
327+
struct cfl_variant *records;
328+
struct cfl_variant *record;
329+
int idx = 0;
330+
331+
cf = flb_cf_yaml_create(NULL, FLB_002, NULL, 0);
332+
TEST_CHECK(cf != NULL);
333+
if (!cf) {
334+
exit(EXIT_FAILURE);
335+
}
336+
337+
/* Total number of sections */
338+
TEST_CHECK(mk_list_size(&cf->sections) == 2);
339+
340+
/* Check number sections per list */
341+
TEST_CHECK(mk_list_size(&cf->parsers) == 0);
342+
TEST_CHECK(mk_list_size(&cf->multiline_parsers) == 0);
343+
TEST_CHECK(mk_list_size(&cf->customs) == 0);
344+
TEST_CHECK(mk_list_size(&cf->inputs) == 1);
345+
TEST_CHECK(mk_list_size(&cf->filters) == 0);
346+
TEST_CHECK(mk_list_size(&cf->outputs) == 1);
347+
TEST_CHECK(mk_list_size(&cf->others) == 0);
348+
349+
/* check inputs */
350+
idx = 0;
351+
mk_list_foreach(head, &cf->inputs) {
352+
s = mk_list_entry(head, struct flb_cf_section, _head_section);
353+
switch (idx) {
354+
case 0:
355+
v = flb_cf_section_property_get(cf, s, "name");
356+
TEST_CHECK(v->type == CFL_VARIANT_STRING);
357+
TEST_CHECK(strcmp(v->data.as_string, "dummy") == 0);
358+
break;
359+
}
360+
idx++;
361+
}
362+
363+
/* check outputs */
364+
idx = 0;
365+
mk_list_foreach(head, &cf->outputs) {
366+
s = mk_list_entry(head, struct flb_cf_section, _head_section);
367+
switch (idx) {
368+
case 0:
369+
v = flb_cf_section_property_get(cf, s, "name");
370+
TEST_CHECK(v->type == CFL_VARIANT_STRING);
371+
TEST_CHECK(strcmp(v->data.as_string, "stdout") == 0);
372+
break;
373+
}
374+
idx++;
375+
}
376+
377+
/* groups */
378+
s = flb_cf_section_get_by_name(cf, "input");
379+
TEST_CHECK(s != NULL);
380+
TEST_CHECK(mk_list_size(&s->groups) == 1);
381+
382+
mk_list_foreach(head, &s->groups) {
383+
g = mk_list_entry(head, struct flb_cf_group, _head);
384+
TEST_CHECK(cfl_list_size(&g->properties->list) == 1);
385+
TEST_CHECK(strcmp(g->name, "processors") == 0);
386+
387+
logs = cfl_kvlist_fetch(g->properties, "logs");
388+
TEST_CHECK(logs != NULL);
389+
if (logs == NULL) {
390+
continue;
391+
}
392+
393+
TEST_CHECK(logs->type == CFL_VARIANT_ARRAY);
394+
if (logs->type == CFL_VARIANT_ARRAY) {
395+
TEST_CHECK(logs->data.as_array->entry_count == 1);
396+
397+
record_modifier_filter = cfl_array_fetch_by_index(logs->data.as_array, 0);
398+
TEST_CHECK(record_modifier_filter != NULL);
399+
400+
if (record_modifier_filter) {
401+
TEST_CHECK(record_modifier_filter->type == CFL_VARIANT_KVLIST);
402+
403+
records = cfl_kvlist_fetch(record_modifier_filter->data.as_kvlist, "record");
404+
TEST_CHECK(records->type == CFL_VARIANT_ARRAY);
405+
TEST_CHECK(records->data.as_array->entry_count == 2);
406+
407+
for (idx = 0; idx < 2; idx++) {
408+
record = cfl_array_fetch_by_index(records->data.as_array, idx);
409+
TEST_CHECK(record->type == CFL_VARIANT_STRING);
410+
411+
if (record->type != CFL_VARIANT_STRING) {
412+
continue;
413+
}
414+
415+
switch (idx) {
416+
case 0:
417+
TEST_CHECK(strcmp(record->data.as_string, "filtered_by record_modifier") == 0);
418+
break;
419+
case 1:
420+
TEST_CHECK(strcmp(record->data.as_string, "powered_by calyptia") == 0);
421+
break;
422+
}
423+
}
424+
}
425+
}
426+
}
427+
428+
flb_cf_destroy(cf);
429+
}
430+
316431
TEST_LIST = {
317432
{ "basic" , test_basic},
318433
{ "customs section", test_customs_section},
319434
{ "slist odd", test_slist_odd},
320435
{ "slist even", test_slist_even},
321436
{ "parsers file conf", test_parser_conf},
322437
{ "camel_case_key", test_camel_case_key},
438+
{ "processors", test_processors},
323439
{ 0 }
324440
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
pipeline:
3+
inputs:
4+
- name: dummy
5+
processors:
6+
logs:
7+
- name: record_modifier
8+
record:
9+
- filtered_by record_modifier
10+
- powered_by calyptia
11+
outputs:
12+
- name: stdout
13+
match: "*"
14+
format: json_lines

0 commit comments

Comments
 (0)