1414
1515#include " google/cloud/connection_options.h"
1616#include " google/cloud/internal/compiler_info.h"
17- #include " google/cloud/internal/setenv.h"
1817#include " google/cloud/log.h"
19- #include " google/cloud/testing_util/environment_variable_restore .h"
18+ #include " google/cloud/testing_util/scoped_environment .h"
2019#include < gmock/gmock.h>
2120#include < map>
2221
@@ -25,7 +24,6 @@ namespace cloud {
2524inline namespace GOOGLE_CLOUD_CPP_NS {
2625namespace {
2726
28- using ::google::cloud::testing_util::EnvironmentVariableRestore;
2927using ::testing::ElementsAre;
3028using ::testing::HasSubstr;
3129using ::testing::StartsWith;
@@ -77,18 +75,14 @@ TEST(ConnectionOptionsTest, Tracing) {
7775}
7876
7977TEST (ConnectionOptionsTest, DefaultTracingUnset) {
80- EnvironmentVariableRestore restore (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" );
81-
82- google::cloud::internal::UnsetEnv (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" );
78+ testing_util::ScopedEnvironment env (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" , {});
8379 TestConnectionOptions options (grpc::InsecureChannelCredentials ());
8480 EXPECT_FALSE (options.tracing_enabled (" rpc" ));
8581}
8682
8783TEST (ConnectionOptionsTest, DefaultTracingSet) {
88- EnvironmentVariableRestore restore (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" );
89-
90- google::cloud::internal::SetEnv (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" ,
91- " foo,bar,baz" );
84+ testing_util::ScopedEnvironment env (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" ,
85+ " foo,bar,baz" );
9286 TestConnectionOptions options (grpc::InsecureChannelCredentials ());
9387 EXPECT_FALSE (options.tracing_enabled (" rpc" ));
9488 EXPECT_TRUE (options.tracing_enabled (" foo" ));
@@ -97,12 +91,10 @@ TEST(ConnectionOptionsTest, DefaultTracingSet) {
9791}
9892
9993TEST (ConnectionOptionsTest, TracingOptions) {
100- EnvironmentVariableRestore restore (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" );
101-
102- google::cloud::internal::SetEnv (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" ,
103- " ,single_line_mode=off"
104- " ,use_short_repeated_primitives=off"
105- " ,truncate_string_field_longer_than=32" );
94+ testing_util::ScopedEnvironment env (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" ,
95+ " ,single_line_mode=off"
96+ " ,use_short_repeated_primitives=off"
97+ " ,truncate_string_field_longer_than=32" );
10698 TestConnectionOptions options (grpc::InsecureChannelCredentials ());
10799 TracingOptions tracing_options = options.tracing_options ();
108100 EXPECT_FALSE (tracing_options.single_line_mode ());
@@ -196,22 +188,20 @@ TEST(ConnectionOptionsTest, CustomBackgroundThreads) {
196188}
197189
198190TEST (ConnectionOptionsTest, DefaultTracingComponentsNoEnvironment) {
199- EnvironmentVariableRestore restore (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" );
200- internal::UnsetEnv (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" );
191+ testing_util::ScopedEnvironment env (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" , {});
201192 auto const actual = internal::DefaultTracingComponents ();
202193 EXPECT_THAT (actual, ElementsAre ());
203194}
204195
205196TEST (ConnectionOptionsTest, DefaultTracingComponentsWithValue) {
206- EnvironmentVariableRestore restore (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" );
207- internal::SetEnv ( " GOOGLE_CLOUD_CPP_ENABLE_TRACING " , " a,b,c" );
197+ testing_util::ScopedEnvironment env (" GOOGLE_CLOUD_CPP_ENABLE_TRACING" ,
198+ " a,b,c" );
208199 auto const actual = internal::DefaultTracingComponents ();
209200 EXPECT_THAT (actual, ElementsAre (" a" , " b" , " c" ));
210201}
211202
212203TEST (ConnectionOptionsTest, DefaultTracingOptionsNoEnvironment) {
213- EnvironmentVariableRestore restore (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" );
214- internal::UnsetEnv (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" );
204+ testing_util::ScopedEnvironment env (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" , {});
215205 auto const actual = internal::DefaultTracingOptions ();
216206 auto const expected = TracingOptions{};
217207 EXPECT_EQ (expected.single_line_mode (), actual.single_line_mode ());
@@ -222,11 +212,10 @@ TEST(ConnectionOptionsTest, DefaultTracingOptionsNoEnvironment) {
222212}
223213
224214TEST (ConnectionOptionsTest, DefaultTracingOptionsWithValue) {
225- EnvironmentVariableRestore restore (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" );
226- internal::SetEnv (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" ,
227- " single_line_mode=on"
228- " ,use_short_repeated_primitives=ON"
229- " ,truncate_string_field_longer_than=42" );
215+ testing_util::ScopedEnvironment env (" GOOGLE_CLOUD_CPP_TRACING_OPTIONS" ,
216+ " single_line_mode=on"
217+ " ,use_short_repeated_primitives=ON"
218+ " ,truncate_string_field_longer_than=42" );
230219 auto const actual = internal::DefaultTracingOptions ();
231220 EXPECT_TRUE (actual.single_line_mode ());
232221 EXPECT_TRUE (actual.use_short_repeated_primitives ());
0 commit comments