xref: /aosp_15_r20/external/grpc-grpc/test/core/config/load_config_test.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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/lib/config/load_config.h"
16 
17 #include "absl/flags/flag.h"
18 #include "gtest/gtest.h"
19 
20 #include "src/core/lib/gprpp/env.h"
21 
22 ABSL_FLAG(std::vector<std::string>, comma_separated_strings, {}, "");
23 
24 namespace grpc_core {
25 
TEST(LoadConfigTest,LoadCommaSeparated)26 TEST(LoadConfigTest, LoadCommaSeparated) {
27   SetEnv("grpc_comma_separated_strings", "foo");
28   EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
29                        "grpc_comma_separated_strings", {}, ""),
30             "foo");
31   EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
32                        "grpc_comma_separated_strings", "bar", ""),
33             "bar");
34   absl::SetFlag(&FLAGS_comma_separated_strings, {"hello"});
35   EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
36                        "grpc_comma_separated_strings", {}, ""),
37             "hello");
38   EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
39                        "grpc_comma_separated_strings", "bar", ""),
40             "bar");
41   absl::SetFlag(&FLAGS_comma_separated_strings, {"hello", "world"});
42   EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
43                        "grpc_comma_separated_strings", {}, ""),
44             "hello,world");
45   EXPECT_EQ(LoadConfig(FLAGS_comma_separated_strings,
46                        "grpc_comma_separated_strings", "bar", ""),
47             "bar");
48 }
49 
50 }  // namespace grpc_core
51 
main(int argc,char ** argv)52 int main(int argc, char** argv) {
53   ::testing::InitGoogleTest(&argc, argv);
54   return RUN_ALL_TESTS();
55 }
56