Skip to content

Commit 9bf9c1b

Browse files
committed
tests: add caller-owned config parse failure cases
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 99d6270 commit 9bf9c1b

6 files changed

Lines changed: 116 additions & 13 deletions

File tree

tests/internal/config_format_fluentbit.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define FLB_003 FLB_TESTS_DATA_PATH "/data/config_format/classic/recursion.conf"
1919
#define FLB_004 FLB_TESTS_DATA_PATH "/data/config_format/classic/issue6281.conf"
2020
#define FLB_005 FLB_TESTS_DATA_PATH "/data/config_format/classic/nolimitline.conf"
21+
#define FLB_006 FLB_TESTS_DATA_PATH "/data/config_format/classic/missing_include.conf"
2122

2223
#define ERROR_LOG "fluentbit_conf_error.log"
2324

@@ -166,7 +167,8 @@ void missing_value()
166167

167168
void indent_level_error()
168169
{
169-
struct flb_cf *cf;
170+
struct flb_cf *cf;
171+
struct flb_cf *ret;
170172
FILE *fp = NULL;
171173
char *expected_strs[] = {"invalid", "indent", "level"};
172174
struct str_list expected = {
@@ -188,44 +190,64 @@ void indent_level_error()
188190
exit(EXIT_FAILURE);
189191
}
190192

191-
cf = flb_cf_fluentbit_create(cf, FLB_002, NULL, 0);
192-
TEST_CHECK(cf == NULL);
193+
ret = flb_cf_fluentbit_create(cf, FLB_002, NULL, 0);
194+
TEST_CHECK(ret == NULL);
193195
fflush(fp);
194196
fclose(fp);
195197

196198
fp = fopen(ERROR_LOG, "r");
197199
if (!TEST_CHECK(fp != NULL)) {
198200
TEST_MSG("fopen failed. errno=%d path=%s", errno, ERROR_LOG);
199-
if (cf != NULL) {
200-
flb_cf_destroy(cf);
201-
}
201+
flb_cf_destroy(cf);
202202
unlink(ERROR_LOG);
203203
exit(EXIT_FAILURE);
204204
}
205205

206206
check_str_list(&expected, fp);
207-
if (cf != NULL) {
208-
flb_cf_destroy(cf);
209-
}
207+
flb_cf_destroy(cf);
210208
fclose(fp);
211209
unlink(ERROR_LOG);
212210
}
213211

214212
void recursion()
215213
{
216-
struct flb_cf *cf;
214+
struct flb_cf *cf;
215+
struct flb_cf *ret;
217216

218217
cf = flb_cf_create();
219218
if (!TEST_CHECK(cf != NULL)) {
220219
TEST_MSG("flb_cf_create failed");
221220
exit(EXIT_FAILURE);
222221
}
223222

224-
cf = flb_cf_fluentbit_create(cf, FLB_003, NULL, 0);
223+
ret = flb_cf_fluentbit_create(cf, FLB_003, NULL, 0);
224+
if (ret != NULL) {
225+
flb_cf_destroy(ret);
226+
}
227+
else {
228+
flb_cf_destroy(cf);
229+
}
225230

226231
/* No SIGSEGV means success */
227232
}
228233

234+
void test_caller_owned_error()
235+
{
236+
struct flb_cf *cf;
237+
struct flb_cf *ret;
238+
239+
cf = flb_cf_create();
240+
if (!TEST_CHECK(cf != NULL)) {
241+
TEST_MSG("flb_cf_create failed");
242+
exit(EXIT_FAILURE);
243+
}
244+
245+
ret = flb_cf_fluentbit_create(cf, FLB_006, NULL, 0);
246+
TEST_CHECK(ret == NULL);
247+
248+
flb_cf_destroy(cf);
249+
}
250+
229251

230252
/*
231253
* https://github.com/fluent/fluent-bit/issues/6281
@@ -346,6 +368,7 @@ TEST_LIST = {
346368
{ "missing_value_issue5880" , missing_value},
347369
{ "indent_level_error" , indent_level_error},
348370
{ "recursion" , recursion},
371+
{ "caller_owned_error" , test_caller_owned_error},
349372
{ "not_current_dir_files", not_current_dir_files},
350373
{ "no_limit_line", test_nolimit_line},
351374
{ "snake_case_key", test_snake_case_key},

tests/internal/config_format_yaml.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
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_007 FLB_TESTS_CONF_PATH "/missing_include.yaml"
3536

3637
#define FLB_000_WIN FLB_TESTS_CONF_PATH "\\fluent-bit-windows.yaml"
3738
#define FLB_BROKEN_PLUGIN_VARIANT FLB_TESTS_CONF_PATH "/broken_plugin_variant.yaml"
@@ -873,6 +874,23 @@ static void test_invalid_property()
873874
}
874875
}
875876

877+
static void test_caller_owned_error()
878+
{
879+
struct flb_cf *cf;
880+
struct flb_cf *ret;
881+
882+
cf = flb_cf_create();
883+
if (!TEST_CHECK(cf != NULL)) {
884+
TEST_MSG("flb_cf_create failed");
885+
exit(EXIT_FAILURE);
886+
}
887+
888+
ret = flb_cf_yaml_create(cf, FLB_007, NULL, 0);
889+
TEST_CHECK(ret == NULL);
890+
891+
flb_cf_destroy(cf);
892+
}
893+
876894
TEST_LIST = {
877895
{ "basic" , test_basic},
878896
{ "customs section", test_customs_section},
@@ -887,5 +905,6 @@ TEST_LIST = {
887905
{ "plugins", test_plugins},
888906
{ "upstream_servers", test_upstream_servers},
889907
{ "invalid_input_property", test_invalid_property},
908+
{ "caller_owned_error", test_caller_owned_error},
890909
{ 0 }
891910
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@INCLUDE missing.conf
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
includes:
2+
- missing.yaml
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
includes:
2+
- missing_reload_include.yaml

tests/internal/reload.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
#include "flb_tests_internal.h"
2121

22-
#define FLB_YAML FLB_TESTS_DATA_PATH "/data/reload/yaml/processor.yaml"
23-
#define FLB_CLASSIC FLB_TESTS_DATA_PATH "/data/reload/fluent-bit.conf"
22+
#define FLB_YAML FLB_TESTS_DATA_PATH "/data/reload/yaml/processor.yaml"
23+
#define FLB_YAML_MISSING_INCLUDE FLB_TESTS_DATA_PATH "/data/reload/yaml/missing_include.yaml"
24+
#define FLB_CLASSIC FLB_TESTS_DATA_PATH "/data/reload/fluent-bit.conf"
2425

2526
void test_reconstruct_cf()
2627
{
@@ -247,6 +248,60 @@ void test_reload_yaml()
247248
flb_destroy(ctx);
248249
}
249250

251+
/* data/reload/yaml/missing_include.yaml */
252+
void test_reload_yaml_missing_include()
253+
{
254+
struct flb_cf *cf = NULL;
255+
struct flb_cf *cf_opts;
256+
struct flb_cf_section *section;
257+
struct cfl_variant *ret;
258+
flb_ctx_t *ctx;
259+
int status;
260+
261+
cf_opts = flb_cf_create();
262+
TEST_CHECK(cf_opts != NULL);
263+
264+
section = flb_cf_section_create(cf_opts, "INPUT", 5);
265+
TEST_CHECK(section != NULL);
266+
267+
ret = flb_cf_section_property_add(cf_opts, section->properties, "name", 0, "dummy", 0);
268+
TEST_CHECK(ret != NULL);
269+
270+
ctx = flb_create();
271+
if (!TEST_CHECK(ctx != NULL)) {
272+
TEST_MSG("flb_create failed");
273+
exit(EXIT_FAILURE);
274+
}
275+
276+
cf = ctx->config->cf_main;
277+
278+
status = flb_reload_reconstruct_cf(cf_opts, cf);
279+
TEST_CHECK(status == 0);
280+
281+
cf = flb_cf_create_from_file(cf, FLB_YAML);
282+
TEST_CHECK(cf != NULL);
283+
284+
ctx->config->conf_path_file = flb_sds_create(FLB_YAML);
285+
ctx->config->enable_hot_reload = FLB_TRUE;
286+
287+
status = flb_config_load_config_format(ctx->config, cf);
288+
TEST_CHECK(status == 0);
289+
290+
status = flb_start(ctx);
291+
TEST_CHECK(status == 0);
292+
293+
flb_sds_destroy(ctx->config->conf_path_file);
294+
ctx->config->conf_path_file = flb_sds_create(FLB_YAML_MISSING_INCLUDE);
295+
296+
status = flb_reload(ctx, cf_opts);
297+
TEST_CHECK(status == FLB_RELOAD_HALTED);
298+
299+
flb_cf_destroy(cf_opts);
300+
301+
flb_stop(ctx);
302+
flb_destroy(ctx);
303+
}
304+
250305
/* Test hot reload watchdog timeout functionality */
251306
#ifndef FLB_SYSTEM_WINDOWS
252307
void test_reload_watchdog_timeout()
@@ -394,6 +449,7 @@ TEST_LIST = {
394449
{ "reconstruct_cf" , test_reconstruct_cf},
395450
{ "reload" , test_reload},
396451
{ "reload_yaml" , test_reload_yaml},
452+
{ "reload_yaml_missing_include", test_reload_yaml_missing_include},
397453
{ "reload_watchdog_timeout", test_reload_watchdog_timeout},
398454
{ 0 }
399455
};

0 commit comments

Comments
 (0)