1 // Copyright 2023 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/core/config/load_config.h"
16
17 #include "absl/flags/flag.h"
18 #include "gtest/gtest.h"
19 #include "src/core/util/env.h"
20
21 ABSL_FLAG(std::vector<std::string>, comma_separated_strings, {}, "");
22
23 namespace grpc_core {
24
TEST(LoadConfigTest,LoadCommaSeparated)25 TEST(LoadConfigTest, LoadCommaSeparated) {
26 SetEnv("grpc_comma_separated_strings", "foo");
27 EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
28 "grpc_comma_separated_strings", {}, ""),
29 "foo");
30 EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
31 "grpc_comma_separated_strings", "bar", ""),
32 "bar");
33 absl::SetFlag(&FLAGS_comma_separated_strings, {"hello"});
34 EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
35 "grpc_comma_separated_strings", {}, ""),
36 "hello");
37 EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
38 "grpc_comma_separated_strings", "bar", ""),
39 "bar");
40 absl::SetFlag(&FLAGS_comma_separated_strings, {"hello", "world"});
41 EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
42 "grpc_comma_separated_strings", {}, ""),
43 "hello,world");
44 EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
45 "grpc_comma_separated_strings", "bar", ""),
46 "bar");
47 }
48
49 } // namespace grpc_core
50
main(int argc,char ** argv)51 int main(int argc, char** argv) {
52 ::testing::InitGoogleTest(&argc, argv);
53 return RUN_ALL_TESTS();
54 }
55