-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: internal: add 'config_format' for fluentbit and YAML
Signed-off-by: Eduardo Silva <[email protected]>
- Loading branch information
Showing
6 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
#include <fluent-bit/flb_info.h> | ||
#include <fluent-bit/flb_mem.h> | ||
#include <fluent-bit/flb_kv.h> | ||
#include <fluent-bit/flb_config_format.h> | ||
|
||
#include "flb_tests_internal.h" | ||
|
||
void test_api() | ||
{ | ||
struct flb_cf *cf; | ||
struct flb_cf_section *s_tmp; | ||
struct flb_cf_section *service; | ||
struct flb_cf_group *g_tmp; | ||
struct flb_kv *meta; | ||
struct flb_kv *kv; | ||
|
||
/* create context */ | ||
cf = flb_cf_create(); | ||
TEST_CHECK(cf != NULL); | ||
|
||
/* create service section */ | ||
service = flb_cf_section_create(cf, "SERVICE", 7); | ||
TEST_CHECK(service != NULL); | ||
|
||
/* add a property */ | ||
kv = flb_cf_property_add(cf, &service->properties, "key", 3, "val", 3); | ||
TEST_CHECK(kv != NULL); | ||
|
||
/* add a property with empty spaces on left/right */ | ||
kv = flb_cf_property_add(cf, &service->properties, " key ", 5, " val ", 7); | ||
TEST_CHECK(kv != NULL); | ||
|
||
/* property: check key */ | ||
TEST_CHECK(flb_sds_len(kv->key) == 3); | ||
TEST_CHECK(strcmp(kv->key, "key") == 0); | ||
|
||
/* property: check val */ | ||
TEST_CHECK(flb_sds_len(kv->key) == 3); | ||
TEST_CHECK(strcmp(kv->key, "key") == 0); | ||
|
||
/* add an invalid property */ | ||
kv = flb_cf_property_add(cf, &service->properties, " ", 3, "", 0); | ||
TEST_CHECK(kv == NULL); | ||
|
||
/* try to add another 'SERVICE' section, it should fail */ | ||
s_tmp = flb_cf_section_create(cf, "SERVICE", 7); | ||
TEST_CHECK(s_tmp == NULL); | ||
|
||
/* add a valid section */ | ||
s_tmp = flb_cf_section_create(cf, "INPUT", 5); | ||
TEST_CHECK(s_tmp != NULL); | ||
|
||
TEST_CHECK(mk_list_size(&cf->inputs) == 1); | ||
|
||
/* add property to the section recently created */ | ||
kv = flb_cf_property_add(cf, &s_tmp->properties, "key", 3, "val", 3); | ||
TEST_CHECK(kv != NULL); | ||
|
||
/* groups: add groups to the last section created */ | ||
g_tmp = flb_cf_group_create(cf, s_tmp, "FLUENT GROUP", 12); | ||
TEST_CHECK(g_tmp != NULL); | ||
|
||
/* add properties to the group */ | ||
kv = flb_cf_property_add(cf, &g_tmp->properties, "key", 3, "val", 3); | ||
TEST_CHECK(kv != NULL); | ||
|
||
/* groups: invalid group */ | ||
g_tmp = flb_cf_group_create(cf, s_tmp, "", 0); | ||
TEST_CHECK(g_tmp == NULL); | ||
|
||
/* Meta commands */ | ||
meta = flb_cf_meta_create(cf, "@SET a=1 ", 20); | ||
TEST_CHECK(meta != NULL); | ||
TEST_CHECK(flb_sds_len(meta->key) == 3 && strcmp(meta->key, "SET") == 0); | ||
TEST_CHECK(flb_sds_len(meta->val) == 3 && strcmp(meta->val, "a=1") == 0); | ||
|
||
/* invalid meta */ | ||
meta = flb_cf_meta_create(cf, "@a=1 ", 5); | ||
TEST_CHECK(meta == NULL); | ||
|
||
/* destroy context */ | ||
flb_cf_destroy(cf); | ||
} | ||
|
||
TEST_LIST = { | ||
{ "api" , test_api}, | ||
{ 0 } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
#include <fluent-bit/flb_info.h> | ||
#include <fluent-bit/flb_mem.h> | ||
#include <fluent-bit/flb_kv.h> | ||
#include <fluent-bit/flb_config_format.h> | ||
|
||
#include "flb_tests_internal.h" | ||
|
||
#define FLB_000 FLB_TESTS_DATA_PATH "/data/config_format/fluent-bit.conf" | ||
|
||
/* data/config_format/fluent-bit.conf */ | ||
void test_basic() | ||
{ | ||
struct flb_cf *cf; | ||
|
||
cf = flb_cf_fluentbit_create(FLB_000, NULL, 0); | ||
TEST_CHECK(cf != NULL); | ||
|
||
/* Total number of sections */ | ||
TEST_CHECK(mk_list_size(&cf->sections) == 8); | ||
|
||
/* SERVICE check */ | ||
TEST_CHECK(cf->service != NULL); | ||
TEST_CHECK(mk_list_size(&cf->service->properties) == 3); | ||
|
||
/* Meta commands */ | ||
TEST_CHECK(mk_list_size(&cf->metas) == 2); | ||
|
||
/* Check number sections per list */ | ||
TEST_CHECK(mk_list_size(&cf->parsers) == 1); | ||
TEST_CHECK(mk_list_size(&cf->multiline_parsers) == 1); | ||
TEST_CHECK(mk_list_size(&cf->customs) == 1); | ||
TEST_CHECK(mk_list_size(&cf->inputs) == 1); | ||
TEST_CHECK(mk_list_size(&cf->filters) == 1); | ||
TEST_CHECK(mk_list_size(&cf->outputs) == 1); | ||
TEST_CHECK(mk_list_size(&cf->others) == 1); | ||
|
||
printf("\n"); | ||
flb_cf_dump(cf); | ||
|
||
flb_cf_destroy(cf); | ||
} | ||
|
||
TEST_LIST = { | ||
{ "basic" , test_basic}, | ||
{ 0 } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
#include <fluent-bit/flb_info.h> | ||
#include <fluent-bit/flb_mem.h> | ||
#include <fluent-bit/flb_kv.h> | ||
#include <fluent-bit/flb_config_format.h> | ||
|
||
#include "flb_tests_internal.h" | ||
|
||
#define FLB_000 FLB_TESTS_DATA_PATH "/data/config_format/fluent-bit.yaml" | ||
|
||
/* data/config_format/fluent-bit.yaml */ | ||
void test_basic() | ||
{ | ||
struct flb_cf *cf; | ||
|
||
cf = flb_cf_yaml_create(FLB_000, NULL, 0); | ||
TEST_CHECK(cf != NULL); | ||
if (!cf) { | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
/* Total number of sections */ | ||
TEST_CHECK(mk_list_size(&cf->sections) == 9); | ||
|
||
/* SERVICE check */ | ||
TEST_CHECK(cf->service != NULL); | ||
|
||
if (cf->service) { | ||
TEST_CHECK(mk_list_size(&cf->service->properties) == 3); | ||
} | ||
|
||
/* 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) == 1); | ||
TEST_CHECK(mk_list_size(&cf->inputs) == 3); | ||
TEST_CHECK(mk_list_size(&cf->filters) == 1); | ||
TEST_CHECK(mk_list_size(&cf->outputs) == 2); | ||
TEST_CHECK(mk_list_size(&cf->others) == 1); | ||
|
||
printf("\n"); | ||
flb_cf_dump(cf); | ||
|
||
flb_cf_destroy(cf); | ||
|
||
|
||
} | ||
|
||
TEST_LIST = { | ||
{ "basic" , test_basic}, | ||
{ 0 } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@SET a=1 | ||
@SET b=2 | ||
|
||
[SERVICE] | ||
flush 1 | ||
log_level info | ||
http_server on | ||
|
||
[PARSER] | ||
name test_api | ||
|
||
[MULTILINE_PARSER] | ||
name abc | ||
|
||
[CUSTOM] | ||
name calyptia | ||
|
||
[INPUT] | ||
name tail | ||
path /var/log/containers/*.log | ||
|
||
[FILTER] | ||
name stdout | ||
match * | ||
|
||
[OUTPUT] | ||
name null | ||
match * | ||
|
||
[UNKNOWN] | ||
name blah |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
service: | ||
flush: 1 | ||
log_level: info | ||
http_server: on | ||
|
||
customs: | ||
calyptia: | ||
api_key: abcdefg | ||
|
||
inputs: | ||
tail: | ||
path: "/var/log/containers/*.log" | ||
parser: docker | ||
|
||
tail: | ||
path: "/var/log/messages" | ||
parser: syslog | ||
|
||
forward: | ||
listen: 0.0.0.0 | ||
|
||
filters: | ||
grep: | ||
exclude: $kubernetes['labels']['app'] myapp | ||
|
||
outputs: | ||
stdout: | ||
match: "*" | ||
retry_limit: false | ||
|
||
http: | ||
match: "*" | ||
host: 192.168.3.2 | ||
port: 9444 | ||
tls: on | ||
tls.verify: off | ||
retry_limit: false | ||
|
||
unknown: | ||
a: b |