fix: Array parsing in new config (#1896)

Improving array parsing in config:
- Allow null values in arrays for optional fields
- Allow empty array even for required field
- Allow to not put an empty array in config even if array contains
required fields
This commit is contained in:
Sergey Kuznetsov
2025-02-18 13:29:43 +00:00
committed by GitHub
parent fcebd715ba
commit 4b178805de
13 changed files with 328 additions and 132 deletions

View File

@@ -80,8 +80,8 @@ using util::config::ConfigValue;
struct LoggerInitTest : LoggerTest {
protected:
util::config::ClioConfigDefinition config_{
{"log_channels.[].channel", Array{ConfigValue{ConfigType::String}.optional()}},
{"log_channels.[].log_level", Array{ConfigValue{ConfigType::String}.optional()}},
{"log_channels.[].channel", Array{ConfigValue{ConfigType::String}}},
{"log_channels.[].log_level", Array{ConfigValue{ConfigType::String}}},
{"log_level", ConfigValue{ConfigType::String}.defaultValue("info")},
@@ -181,9 +181,15 @@ TEST_F(LoggerInitTest, LogSizeAndHourRotationCannotBeZero)
"log_rotation_hour_interval", "log_directory_max_size", "log_rotation_size"
};
auto const jsonStr = fmt::format(R"json({{
"{}": 0,
"{}": 0,
"{}": 0
}})json", keys[0], keys[1], keys[2]);
auto const parsingErrors =
config_.parse(ConfigFileJson{boost::json::object{{keys[0], 0}, {keys[1], 0}, {keys[2], 0}}});
ASSERT_TRUE(parsingErrors->size() == 3);
config_.parse(ConfigFileJson{boost::json::parse(jsonStr).as_object()});
ASSERT_EQ(parsingErrors->size(), 3);
for (std::size_t i = 0; i < parsingErrors->size(); ++i) {
EXPECT_EQ(
(*parsingErrors)[i].error,