Skip to content

Commit cf0220e

Browse files
Return sorted validAzureCloudNameValues
This ensures that the list validAzureCloudNameValues is in a stable order, making testing a lot more straight forward
1 parent 24664ed commit cf0220e

2 files changed

Lines changed: 5 additions & 21 deletions

File tree

pkg/cloud/azure/azure.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"embed"
55
"encoding/json"
66
"fmt"
7+
"slices"
78
"strings"
89

910
"github.com/asaskevich/govalidator"
@@ -44,6 +45,7 @@ var (
4445
for n := range validAzureCloudNames {
4546
v = append(v, string(n))
4647
}
48+
slices.Sort(v)
4749
return v
4850
}()
4951
)

pkg/cloud/azure/azure_test.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ func TestCloudConfigTransformer(t *testing.T) {
142142
infra: makeInfrastructureResource(configv1.AzurePlatformType, configv1.AzureStackCloud),
143143
errMsg: fmt.Sprintf("invalid platform, expected CloudName to be %s", configv1.AzurePublicCloud),
144144
},
145-
{ // extend this to include Cloud so we don't duplicate
146-
name: "Azure sets the vmType to standard",
145+
{
146+
name: "Azure sets the vmType to standard and cloud to AzurePublicCloud when neither is set",
147147
source: azure.Config{},
148148
expected: azure.Config{VMType: "standard", AzureAuthConfig: ratelimitconfig.AzureAuthConfig{Cloud: string(configv1.AzurePublicCloud)}},
149149
infra: makeInfrastructureResource(configv1.AzurePlatformType, configv1.AzurePublicCloud),
@@ -154,18 +154,6 @@ func TestCloudConfigTransformer(t *testing.T) {
154154
expected: azure.Config{VMType: "vmss", AzureAuthConfig: ratelimitconfig.AzureAuthConfig{Cloud: string(configv1.AzurePublicCloud)}},
155155
infra: makeInfrastructureResource(configv1.AzurePlatformType, configv1.AzurePublicCloud),
156156
},
157-
{
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-
},
169157
{
170158
name: "Azure sets the cloud to AzurePublicCloud and keeps existing fields",
171159
source: azure.Config{
@@ -198,15 +186,11 @@ func TestCloudConfigTransformer(t *testing.T) {
198186
expected: azure.Config{VMType: "standard", AzureAuthConfig: ratelimitconfig.AzureAuthConfig{Cloud: string(configv1.AzureGermanCloud)}},
199187
infra: makeInfrastructureResource(configv1.AzurePlatformType, configv1.AzureGermanCloud),
200188
},
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
205189
{
206190
name: "Azure throws an error if the infra has an invalid cloud",
207191
source: azure.Config{},
208192
infra: makeInfrastructureResource(configv1.AzurePlatformType, "AzureAnotherCloud"),
209-
errMsg: "status.platformStatus.azure.cloudName: Unsupported value: \"AzureAnotherCloud\": supported values: \"AzurePublicCloud\", \"AzureUSGovernmentCloud\", \"AzureChinaCloud\", \"AzureGermanCloud\", \"AzureStackCloud\"",
193+
errMsg: "status.platformStatus.azure.cloudName: Unsupported value: \"AzureAnotherCloud\": supported values: \"AzureChinaCloud\", \"AzureGermanCloud\", \"AzurePublicCloud\", \"AzureStackCloud\", \"AzureUSGovernmentCloud\"",
210194
},
211195
{
212196
name: "Azure keeps the cloud set in the source when there is not one set in infrastructure",
@@ -249,8 +233,6 @@ func TestCloudConfigTransformer(t *testing.T) {
249233

250234
actual, err := CloudConfigTransformer(string(src), tc.infra, nil)
251235
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())
254236
g.Expect(err).Should(MatchError(tc.errMsg))
255237
g.Expect(actual).Should(Equal(""))
256238
} else {

0 commit comments

Comments
 (0)