@@ -86,6 +86,7 @@ func TestGetCloudFromYAML(t *testing.T) {
8686
8787func TestGetCloudFromYAMLOSCLOUD (t * testing.T ) {
8888 os .Setenv ("OS_CLOUD" , "california" )
89+ defer os .Unsetenv ("OS_CLOUD" )
8990
9091 clientOpts := & clientconfig.ClientOpts {
9192 Cloud : "hawaii" ,
@@ -94,18 +95,15 @@ func TestGetCloudFromYAMLOSCLOUD(t *testing.T) {
9495 actual , err := clientconfig .GetCloudFromYAML (clientOpts )
9596 th .AssertNoErr (t , err )
9697 th .AssertDeepEquals (t , & HawaiiCloudYAML , actual )
97-
98- os .Unsetenv ("OS_CLOUD" )
9998}
10099
101100func TestGetCloudFromYAMLMissingClientOpts (t * testing.T ) {
102101 os .Setenv ("OS_CLOUD" , "california" )
102+ defer os .Unsetenv ("OS_CLOUD" )
103103
104104 actual , err := clientconfig .GetCloudFromYAML (nil )
105105 th .AssertNoErr (t , err )
106106 th .AssertDeepEquals (t , & CaliforniaCloudYAML , actual )
107-
108- os .Unsetenv ("OS_CLOUD" )
109107}
110108
111109func TestAuthOptionsExplicitCloud (t * testing.T ) {
@@ -125,6 +123,7 @@ func TestAuthOptionsExplicitCloud(t *testing.T) {
125123
126124func TestAuthOptionsOSCLOUD (t * testing.T ) {
127125 os .Setenv ("FOO_CLOUD" , "hawaii" )
126+ defer os .Unsetenv ("FOO_CLOUD" )
128127
129128 clientOpts := & clientconfig.ClientOpts {
130129 EnvPrefix : "FOO_" ,
@@ -136,12 +135,11 @@ func TestAuthOptionsOSCLOUD(t *testing.T) {
136135 }
137136
138137 th .AssertDeepEquals (t , HawaiiAuthOpts , actual )
139-
140- os .Unsetenv ("FOO_CLOUD" )
141138}
142139
143140func TestAuthOptionsExplicitCloudAndOSCLOUD (t * testing.T ) {
144141 os .Setenv ("FOO_CLOUD" , "hawaii" )
142+ defer os .Unsetenv ("FOO_CLOUD" )
145143
146144 clientOpts := & clientconfig.ClientOpts {
147145 EnvPrefix : "FOO_" ,
@@ -155,12 +153,11 @@ func TestAuthOptionsExplicitCloudAndOSCLOUD(t *testing.T) {
155153
156154 // We should have ignored the cloud configuration option
157155 th .AssertDeepEquals (t , CaliforniaAuthOpts , actual )
158-
159- os .Unsetenv ("FOO_CLOUD" )
160156}
161157
162158func TestAuthOptionsMissingClientOpts (t * testing.T ) {
163159 os .Setenv ("OS_CLOUD" , "hawaii" )
160+ defer os .Unsetenv ("OS_CLOUD" )
164161
165162 actual , err := clientconfig .AuthOptions (nil )
166163 if err != nil {
@@ -170,8 +167,6 @@ func TestAuthOptionsMissingClientOpts(t *testing.T) {
170167 // We should have handled the missing config opts and fallen back to
171168 // defaults
172169 th .AssertDeepEquals (t , HawaiiAuthOpts , actual )
173-
174- os .Unsetenv ("OS_CLOUD" )
175170}
176171
177172func TestAuthOptionsCreationFromCloudsYAML (t * testing.T ) {
@@ -304,15 +299,12 @@ func TestAuthOptionsCreationFromEnv(t *testing.T) {
304299 for cloud , envVars := range allEnvVars {
305300 for k , v := range envVars {
306301 os .Setenv (k , v )
302+ defer os .Unsetenv (k )
307303 }
308304
309305 actualAuthOpts , err := clientconfig .AuthOptions (nil )
310306 th .AssertNoErr (t , err )
311307 th .AssertDeepEquals (t , expectedAuthOpts [cloud ], actualAuthOpts )
312-
313- for k := range envVars {
314- os .Unsetenv (k )
315- }
316308 }
317309}
318310
@@ -332,15 +324,12 @@ func TestAuthOptionsCreationFromLegacyEnv(t *testing.T) {
332324 for cloud , envVars := range allEnvVars {
333325 for k , v := range envVars {
334326 os .Setenv (k , v )
327+ defer os .Unsetenv (k )
335328 }
336329
337330 actualAuthOpts , err := clientconfig .AuthOptions (nil )
338331 th .AssertNoErr (t , err )
339332 th .AssertDeepEquals (t , expectedAuthOpts [cloud ], actualAuthOpts )
340-
341- for k := range envVars {
342- os .Unsetenv (k )
343- }
344333 }
345334}
346335
0 commit comments