|
| 1 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | + |
| 3 | +#include <fluent-bit/flb_config.h> |
| 4 | +#include <fluent-bit/flb_config_format.h> |
| 5 | + |
| 6 | +#include "flb_tests_internal.h" |
| 7 | + |
| 8 | +#define UNKNOWN_YAML_CONFIG \ |
| 9 | + FLB_TESTS_DATA_PATH "/data/config_format/yaml/unknown_service.yaml" |
| 10 | + |
| 11 | +static void test_service_property_validation(void) |
| 12 | +{ |
| 13 | + TEST_CHECK(flb_config_service_property_is_valid("flush") == FLB_TRUE); |
| 14 | + TEST_CHECK(flb_config_service_property_is_valid("Log_Level") == FLB_TRUE); |
| 15 | + TEST_CHECK(flb_config_service_property_is_valid("log_livel") == FLB_FALSE); |
| 16 | + TEST_CHECK(flb_config_service_property_is_valid("another_param") == FLB_FALSE); |
| 17 | +} |
| 18 | + |
| 19 | +static void test_unknown_service_property_compatibility(void) |
| 20 | +{ |
| 21 | + int ret; |
| 22 | + int verbose; |
| 23 | + struct flb_log *log; |
| 24 | + struct flb_config *config; |
| 25 | + |
| 26 | + config = flb_config_init(); |
| 27 | + TEST_CHECK(config != NULL); |
| 28 | + if (config == NULL) { |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + log = config->log; |
| 33 | + verbose = config->verbose; |
| 34 | + |
| 35 | + ret = flb_config_set_property(config, "log_livel", "debug"); |
| 36 | + TEST_CHECK(ret == 0); |
| 37 | + TEST_CHECK(config->log == log); |
| 38 | + TEST_CHECK(config->verbose == verbose); |
| 39 | + |
| 40 | + flb_config_exit(config); |
| 41 | +} |
| 42 | + |
| 43 | +static void test_section_name_validation(void) |
| 44 | +{ |
| 45 | + struct flb_cf *cf; |
| 46 | + struct flb_cf_section *section; |
| 47 | + |
| 48 | + cf = flb_cf_create(); |
| 49 | + TEST_CHECK(cf != NULL); |
| 50 | + if (cf == NULL) { |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + section = flb_cf_section_create(cf, "SERVIC", 0); |
| 55 | + TEST_CHECK(section != NULL); |
| 56 | + TEST_CHECK(section->type == FLB_CF_OTHER); |
| 57 | + TEST_CHECK(cf->service == NULL); |
| 58 | + |
| 59 | + flb_cf_destroy(cf); |
| 60 | +} |
| 61 | + |
| 62 | +static void test_classic_unknown_configuration_load(void) |
| 63 | +{ |
| 64 | + int ret; |
| 65 | + struct cfl_variant *property; |
| 66 | + struct flb_cf *cf; |
| 67 | + struct flb_cf_section *section; |
| 68 | + struct flb_config *config; |
| 69 | + |
| 70 | + cf = flb_cf_create(); |
| 71 | + TEST_CHECK(cf != NULL); |
| 72 | + if (cf == NULL) { |
| 73 | + return; |
| 74 | + } |
| 75 | + |
| 76 | + flb_cf_set_origin_format(cf, FLB_CF_CLASSIC); |
| 77 | + |
| 78 | + section = flb_cf_section_create(cf, "service", 0); |
| 79 | + TEST_CHECK(section != NULL); |
| 80 | + property = flb_cf_section_property_add(cf, section->properties, |
| 81 | + "another_param", 0, "0", 0); |
| 82 | + TEST_CHECK(property != NULL); |
| 83 | + |
| 84 | + section = flb_cf_section_create(cf, "something", 0); |
| 85 | + TEST_CHECK(section != NULL); |
| 86 | + |
| 87 | + config = flb_config_init(); |
| 88 | + TEST_CHECK(config != NULL); |
| 89 | + if (config != NULL) { |
| 90 | + ret = flb_config_load_config_format(config, cf); |
| 91 | + TEST_CHECK(ret == 0); |
| 92 | + flb_config_exit(config); |
| 93 | + } |
| 94 | + |
| 95 | + flb_cf_destroy(cf); |
| 96 | +} |
| 97 | + |
| 98 | +#ifdef FLB_HAVE_LIBYAML |
| 99 | +static void test_yaml_unknown_configuration_load(void) |
| 100 | +{ |
| 101 | + int ret; |
| 102 | + struct flb_cf *cf; |
| 103 | + struct flb_config *config; |
| 104 | + |
| 105 | + cf = flb_cf_yaml_create(NULL, UNKNOWN_YAML_CONFIG, NULL, 0); |
| 106 | + TEST_CHECK(cf != NULL); |
| 107 | + if (cf == NULL) { |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + config = flb_config_init(); |
| 112 | + TEST_CHECK(config != NULL); |
| 113 | + if (config != NULL) { |
| 114 | + ret = flb_config_load_config_format(config, cf); |
| 115 | + TEST_CHECK(ret == 0); |
| 116 | + flb_config_exit(config); |
| 117 | + } |
| 118 | + |
| 119 | + flb_cf_destroy(cf); |
| 120 | +} |
| 121 | +#endif |
| 122 | + |
| 123 | +TEST_LIST = { |
| 124 | + { "service_property_validation", test_service_property_validation }, |
| 125 | + { "unknown_service_property_compatibility", |
| 126 | + test_unknown_service_property_compatibility }, |
| 127 | + { "section_name_validation", test_section_name_validation }, |
| 128 | + { "classic_unknown_configuration_load", test_classic_unknown_configuration_load }, |
| 129 | +#ifdef FLB_HAVE_LIBYAML |
| 130 | + { "yaml_unknown_configuration_load", test_yaml_unknown_configuration_load }, |
| 131 | +#endif |
| 132 | + { 0 } |
| 133 | +}; |
0 commit comments