File tree Expand file tree Collapse file tree 3 files changed +56
-1
lines changed
universal/src/yaml_config Expand file tree Collapse file tree 3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -425,6 +425,37 @@ additionalProperties: false
425425 UEXPECT_NO_THROW (Validate (static_config, schema));
426426}
427427
428+ TEST (StaticConfigValidator, ArrayWithEnvPassed) {
429+ const std::string static_config = R"(
430+ component:
431+ values:
432+ - value#env: ENV_VALUE
433+ )" ;
434+
435+ const std::string schema = R"(
436+ type: object
437+ description: test component with nested array
438+ additionalProperties: false
439+ properties:
440+ values:
441+ type: array
442+ description: values
443+ items:
444+ type: object
445+ additionalProperties: false
446+ properties:
447+ value:
448+ type: string
449+ description: value
450+ )" ;
451+
452+ UEXPECT_THROW (Validate (static_config, schema), formats::yaml::MemberMissingException);
453+
454+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
455+ ::setenv (" ENV_VALUE" , " 100" , 1 );
456+ UEXPECT_THROW (Validate (static_config, schema), formats::yaml::MemberMissingException);
457+ }
458+
428459TEST (StaticConfigValidator, Enum) {
429460 const std::string correct_static_config = R"(
430461mode: on
Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ YamlConfig YamlConfig::operator[](size_t index) const {
227227 return MakeMissingConfig (*this , index)[value.As <std::string>()];
228228 }
229229
230- return {std::move (value), config_vars_};
230+ return {std::move (value), config_vars_, mode_ };
231231}
232232
233233std::size_t YamlConfig::GetSize () const { return yaml_.GetSize (); }
Original file line number Diff line number Diff line change @@ -93,6 +93,30 @@ TEST(YamlConfig, SampleEnv) {
9393 // / [sample env]
9494}
9595
96+ TEST (YamlConfig, SampleEnvInArray) {
97+ auto node = formats::yaml::FromString (R"(
98+ some_elements:
99+ - some#env: ENV_VARIABLE_NAME_1
100+ - some#env: ENV_VARIABLE_NAME_2
101+ )" );
102+
103+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
104+ ::setenv (" ENV_VARIABLE_NAME_1" , " 100" , 1 );
105+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
106+ ::setenv (" ENV_VARIABLE_NAME_2" , " 100" , 1 );
107+
108+ const yaml_config::YamlConfig yaml (std::move (node), {}, yaml_config::YamlConfig::Mode::kEnvAllowed );
109+ const auto & array = yaml[" some_elements" ];
110+ for (const auto & element : array) {
111+ EXPECT_EQ (element[" some" ].As <int >(), 100 );
112+ }
113+
114+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
115+ ::unsetenv (" ENV_VARIABLE_NAME_1" );
116+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
117+ ::unsetenv (" ENV_VARIABLE_NAME_2" );
118+ }
119+
96120TEST (YamlConfig, SampleMultiple) {
97121 const auto node = formats::yaml::FromString (R"(
98122# /// [sample multiple]
You can’t perform that action at this time.
0 commit comments