@@ -84,6 +84,28 @@ func TestGetCloudFromYAML(t *testing.T) {
8484 }
8585}
8686
87+ func TestGetCloudFromYAMLOSCLOUD (t * testing.T ) {
88+ os .Setenv ("OS_CLOUD" , "california" )
89+ defer os .Unsetenv ("OS_CLOUD" )
90+
91+ clientOpts := & clientconfig.ClientOpts {
92+ Cloud : "hawaii" ,
93+ }
94+
95+ actual , err := clientconfig .GetCloudFromYAML (clientOpts )
96+ th .AssertNoErr (t , err )
97+ th .AssertDeepEquals (t , & HawaiiCloudYAML , actual )
98+ }
99+
100+ func TestGetCloudFromYAMLMissingClientOpts (t * testing.T ) {
101+ os .Setenv ("OS_CLOUD" , "california" )
102+ defer os .Unsetenv ("OS_CLOUD" )
103+
104+ actual , err := clientconfig .GetCloudFromYAML (nil )
105+ th .AssertNoErr (t , err )
106+ th .AssertDeepEquals (t , & CaliforniaCloudYAML , actual )
107+ }
108+
87109func TestAuthOptionsExplicitCloud (t * testing.T ) {
88110 os .Unsetenv ("OS_CLOUD" )
89111
@@ -101,6 +123,7 @@ func TestAuthOptionsExplicitCloud(t *testing.T) {
101123
102124func TestAuthOptionsOSCLOUD (t * testing.T ) {
103125 os .Setenv ("FOO_CLOUD" , "hawaii" )
126+ defer os .Unsetenv ("FOO_CLOUD" )
104127
105128 clientOpts := & clientconfig.ClientOpts {
106129 EnvPrefix : "FOO_" ,
@@ -112,8 +135,38 @@ func TestAuthOptionsOSCLOUD(t *testing.T) {
112135 }
113136
114137 th .AssertDeepEquals (t , HawaiiAuthOpts , actual )
138+ }
139+
140+ func TestAuthOptionsExplicitCloudAndOSCLOUD (t * testing.T ) {
141+ os .Setenv ("FOO_CLOUD" , "hawaii" )
142+ defer os .Unsetenv ("FOO_CLOUD" )
143+
144+ clientOpts := & clientconfig.ClientOpts {
145+ EnvPrefix : "FOO_" ,
146+ Cloud : "california" ,
147+ }
115148
116- os .Unsetenv ("FOO_CLOUD" )
149+ actual , err := clientconfig .AuthOptions (clientOpts )
150+ if err != nil {
151+ t .Fatal (err )
152+ }
153+
154+ // We should have ignored the cloud configuration option
155+ th .AssertDeepEquals (t , CaliforniaAuthOpts , actual )
156+ }
157+
158+ func TestAuthOptionsMissingClientOpts (t * testing.T ) {
159+ os .Setenv ("OS_CLOUD" , "hawaii" )
160+ defer os .Unsetenv ("OS_CLOUD" )
161+
162+ actual , err := clientconfig .AuthOptions (nil )
163+ if err != nil {
164+ t .Fatal (err )
165+ }
166+
167+ // We should have handled the missing config opts and fallen back to
168+ // defaults
169+ th .AssertDeepEquals (t , HawaiiAuthOpts , actual )
117170}
118171
119172func TestAuthOptionsCreationFromCloudsYAML (t * testing.T ) {
@@ -246,15 +299,12 @@ func TestAuthOptionsCreationFromEnv(t *testing.T) {
246299 for cloud , envVars := range allEnvVars {
247300 for k , v := range envVars {
248301 os .Setenv (k , v )
302+ defer os .Unsetenv (k )
249303 }
250304
251305 actualAuthOpts , err := clientconfig .AuthOptions (nil )
252306 th .AssertNoErr (t , err )
253307 th .AssertDeepEquals (t , expectedAuthOpts [cloud ], actualAuthOpts )
254-
255- for k := range envVars {
256- os .Unsetenv (k )
257- }
258308 }
259309}
260310
@@ -274,15 +324,12 @@ func TestAuthOptionsCreationFromLegacyEnv(t *testing.T) {
274324 for cloud , envVars := range allEnvVars {
275325 for k , v := range envVars {
276326 os .Setenv (k , v )
327+ defer os .Unsetenv (k )
277328 }
278329
279330 actualAuthOpts , err := clientconfig .AuthOptions (nil )
280331 th .AssertNoErr (t , err )
281332 th .AssertDeepEquals (t , expectedAuthOpts [cloud ], actualAuthOpts )
282-
283- for k := range envVars {
284- os .Unsetenv (k )
285- }
286333 }
287334}
288335
0 commit comments