1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18
19 #include "src/core/util/env.h"
20
21 #include "absl/log/log.h"
22 #include "gtest/gtest.h"
23 #include "test/core/test_util/test_config.h"
24
TEST(EnvTest,SetenvGetenv)25 TEST(EnvTest, SetenvGetenv) {
26 const char* name = "FOO";
27 const char* value = "BAR";
28
29 LOG(INFO) << "test_setenv_getenv";
30
31 grpc_core::SetEnv(name, value);
32 auto retrieved_value = grpc_core::GetEnv(name);
33 ASSERT_EQ(value, retrieved_value);
34 }
35
TEST(EnvTest,Unsetenv)36 TEST(EnvTest, Unsetenv) {
37 const char* name = "FOO";
38 const char* value = "BAR";
39
40 LOG(INFO) << "test_unsetenv";
41
42 grpc_core::SetEnv(name, value);
43 grpc_core::UnsetEnv(name);
44 auto retrieved_value = grpc_core::GetEnv(name);
45 ASSERT_FALSE(retrieved_value.has_value());
46 }
47
main(int argc,char ** argv)48 int main(int argc, char** argv) {
49 grpc::testing::TestEnvironment env(&argc, argv);
50 ::testing::InitGoogleTest(&argc, argv);
51 return RUN_ALL_TESTS();
52 }
53