Skip to content

Commit 22a786a

Browse files
committed
Fix client config unit tests
Commit b2ceaa8 broke some the unit tests by deferring the cleanup of environment variables to when the function exits. Wrap each test in it's own test function so that cleanup happens when needed.
1 parent d0ab9f2 commit 22a786a

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

openstack/clientconfig/testing/requests_test.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,16 @@ func TestAuthOptionsCreationFromEnv(t *testing.T) {
297297
}
298298

299299
for cloud, envVars := range allEnvVars {
300-
for k, v := range envVars {
301-
os.Setenv(k, v)
302-
defer os.Unsetenv(k)
303-
}
300+
t.Run(cloud, func(t *testing.T) {
301+
for k, v := range envVars {
302+
os.Setenv(k, v)
303+
defer os.Unsetenv(k)
304+
}
304305

305-
actualAuthOpts, err := clientconfig.AuthOptions(nil)
306-
th.AssertNoErr(t, err)
307-
th.AssertDeepEquals(t, expectedAuthOpts[cloud], actualAuthOpts)
306+
actualAuthOpts, err := clientconfig.AuthOptions(nil)
307+
th.AssertNoErr(t, err)
308+
th.AssertDeepEquals(t, expectedAuthOpts[cloud], actualAuthOpts)
309+
})
308310
}
309311
}
310312

@@ -322,14 +324,16 @@ func TestAuthOptionsCreationFromLegacyEnv(t *testing.T) {
322324
}
323325

324326
for cloud, envVars := range allEnvVars {
325-
for k, v := range envVars {
326-
os.Setenv(k, v)
327-
defer os.Unsetenv(k)
328-
}
329-
330-
actualAuthOpts, err := clientconfig.AuthOptions(nil)
331-
th.AssertNoErr(t, err)
332-
th.AssertDeepEquals(t, expectedAuthOpts[cloud], actualAuthOpts)
327+
t.Run(cloud, func(t *testing.T) {
328+
for k, v := range envVars {
329+
os.Setenv(k, v)
330+
defer os.Unsetenv(k)
331+
}
332+
333+
actualAuthOpts, err := clientconfig.AuthOptions(nil)
334+
th.AssertNoErr(t, err)
335+
th.AssertDeepEquals(t, expectedAuthOpts[cloud], actualAuthOpts)
336+
})
333337
}
334338
}
335339

0 commit comments

Comments
 (0)