@@ -137,6 +137,12 @@ func TestCloudConfigTransformer(t *testing.T) {
137137 errMsg string
138138 }{
139139 {
140+ name : "Non Azure returns an error" ,
141+ source : azure.Config {},
142+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureStackCloud ),
143+ errMsg : fmt .Sprintf ("invalid platform, expected CloudName to be %s" , configv1 .AzurePublicCloud ),
144+ },
145+ { // extend this to include Cloud so we don't duplicate
140146 name : "Azure sets the vmType to standard" ,
141147 source : azure.Config {},
142148 expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
@@ -149,10 +155,88 @@ func TestCloudConfigTransformer(t *testing.T) {
149155 infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
150156 },
151157 {
152- name : "Non Azure returns an error" ,
158+ name : "Azure sets the cloud to AzurePublicCloud" ,
159+ source : azure.Config {},
160+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
161+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
162+ },
163+ {
164+ name : "Azure sets the cloud to AzurePublicCloud" ,
165+ source : azure.Config {},
166+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
167+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
168+ },
169+ {
170+ name : "Azure sets the cloud to AzurePublicCloud and keeps existing fields" ,
171+ source : azure.Config {
172+ ResourceGroup : "test-rg" ,
173+ },
174+ expected : azure.Config {VMType : "standard" , ResourceGroup : "test-rg" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
175+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
176+ },
177+ {
178+ name : "Azure keeps the cloud set to AzurePublicCloud" ,
179+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
180+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
181+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
182+ },
183+ {
184+ name : "Azure keeps the cloud set to US Gov cloud" ,
185+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzureUSGovernmentCloud )}},
186+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzureUSGovernmentCloud )}},
187+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureUSGovernmentCloud ),
188+ },
189+ {
190+ name : "Azure keeps the cloud set to China cloud" ,
191+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzureChinaCloud )}},
192+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzureChinaCloud )}},
193+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureChinaCloud ),
194+ },
195+ {
196+ name : "Azure keeps the cloud set to German cloud" ,
197+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzureGermanCloud )}},
198+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzureGermanCloud )}},
199+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureGermanCloud ),
200+ },
201+ // The matcher should assert err.Error == errMsg - but is not for some
202+ // reason? According to:
203+ // https://onsi.github.io/gomega/#matcherrorexpected-interface the matcher
204+ // asserts that ACTUAL.Error() == EXPECTED
205+ {
206+ name : "Azure throws an error if the infra has an invalid cloud" ,
153207 source : azure.Config {},
154- infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureStackCloud ),
155- errMsg : fmt .Sprintf ("invalid platform, expected CloudName to be %s" , configv1 .AzurePublicCloud ),
208+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , "AzureAnotherCloud" ),
209+ errMsg : "status.platformStatus.azure.cloudName: Unsupported value: \" AzureAnotherCloud\" : supported values: \" AzurePublicCloud\" , \" AzureUSGovernmentCloud\" , \" AzureChinaCloud\" , \" AzureGermanCloud\" , \" AzureStackCloud\" " ,
210+ },
211+ {
212+ name : "Azure keeps the cloud set in the source when there is not one set in infrastructure" ,
213+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
214+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
215+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , "" ),
216+ },
217+ {
218+ name : "Azure sets the cloud to match the infrastructure if an empty string is provided in source" ,
219+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : "" }},
220+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
221+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
222+ },
223+ {
224+ name : "Azure sets the cloud to match the infrastructure if an empty string is provided in source and the infrastructure is non standard" ,
225+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : "" }},
226+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzureUSGovernmentCloud )}},
227+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureUSGovernmentCloud ),
228+ },
229+ {
230+ name : "Azure returns an error if the source config conflicts with the infrastructure" ,
231+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
232+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzureUSGovernmentCloud ),
233+ errMsg : "invalid user-provided cloud.conf: \\ \" cloud\\ \" field in user-provided\n \t \t \t \t cloud.conf conflicts with infrastructure object" ,
234+ },
235+ {
236+ name : "Azure keeps the cloud set to AzurePublicCloud if the source is upper case" ,
237+ source : azure.Config {AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : "AZUREPUBLICCLOUD" }},
238+ expected : azure.Config {VMType : "standard" , AzureAuthConfig : ratelimitconfig.AzureAuthConfig {Cloud : string (configv1 .AzurePublicCloud )}},
239+ infra : makeInfrastructureResource (configv1 .AzurePlatformType , configv1 .AzurePublicCloud ),
156240 },
157241 }
158242
@@ -165,12 +249,13 @@ func TestCloudConfigTransformer(t *testing.T) {
165249
166250 actual , err := CloudConfigTransformer (string (src ), tc .infra , nil )
167251 if tc .errMsg != "" {
252+ // TODO: Remove once the above error case is working correctly
253+ fmt .Printf ("\n \n err.Error():%s:\n \n " , err .Error ())
168254 g .Expect (err ).Should (MatchError (tc .errMsg ))
169255 g .Expect (actual ).Should (Equal ("" ))
170256 } else {
171257 var observed azure.Config
172258 g .Expect (json .Unmarshal ([]byte (actual ), & observed )).To (Succeed (), "Unmarshal of observed data should succeed" )
173-
174259 g .Expect (observed ).Should (Equal (tc .expected ))
175260 }
176261 })
0 commit comments