|
14 | 14 | #define FLB_TESTS_CONF_PATH FLB_TESTS_DATA_PATH "/data/config_format/yaml" |
15 | 15 | #define FLB_000 FLB_TESTS_CONF_PATH "/fluent-bit.yaml" |
16 | 16 | #define FLB_001 FLB_TESTS_CONF_PATH "/issue_7559.yaml" |
| 17 | +#define FLB_002 FLB_TESTS_CONF_PATH "/processors.yaml" |
17 | 18 |
|
18 | 19 | /* |
19 | 20 | * Configurations to test: |
@@ -47,7 +48,7 @@ static void test_basic() |
47 | 48 | /* Total number of sections */ |
48 | 49 | TEST_CHECK(mk_list_size(&cf->sections) == 9); |
49 | 50 |
|
50 | | - /* SERVICE check */ |
| 51 | + /* SERVICE check */ |
51 | 52 | TEST_CHECK(cf->service != NULL); |
52 | 53 | if (cf->service) { |
53 | 54 | TEST_CHECK(cfl_list_size(&cf->service->properties->list) == 3); |
@@ -262,8 +263,8 @@ static void test_parser_conf() |
262 | 263 | /* Total number of inputs */ |
263 | 264 | if(!TEST_CHECK(mk_list_size(&config->parsers) == cnt+1)) { |
264 | 265 | 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); |
267 | 268 | } |
268 | 269 |
|
269 | 270 | flb_cf_dump(cf); |
@@ -313,12 +314,127 @@ static void test_camel_case_key() |
313 | 314 |
|
314 | 315 | } |
315 | 316 |
|
| 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 | + |
316 | 431 | TEST_LIST = { |
317 | 432 | { "basic" , test_basic}, |
318 | 433 | { "customs section", test_customs_section}, |
319 | 434 | { "slist odd", test_slist_odd}, |
320 | 435 | { "slist even", test_slist_even}, |
321 | 436 | { "parsers file conf", test_parser_conf}, |
322 | 437 | { "camel_case_key", test_camel_case_key}, |
| 438 | + { "processors", test_processors}, |
323 | 439 | { 0 } |
324 | 440 | }; |
0 commit comments