Skip to content

Commit 8873d97

Browse files
committed
Update unit test function sigs
1 parent 5b0ac4a commit 8873d97

16 files changed

+82
-78
lines changed

api/v1beta1/azurecluster_webhook_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
2021
"testing"
2122

2223
. "github.com/onsi/gomega"
@@ -108,7 +109,7 @@ func TestAzureCluster_ValidateCreate(t *testing.T) {
108109
for _, tc := range tests {
109110
t.Run(tc.name, func(t *testing.T) {
110111
g := NewWithT(t)
111-
_, err := tc.cluster.ValidateCreate()
112+
_, err := tc.cluster.ValidateCreate(context.TODO(), nil)
112113
if tc.wantErr {
113114
g.Expect(err).To(HaveOccurred())
114115
} else {
@@ -344,7 +345,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
344345
t.Run(tc.name, func(t *testing.T) {
345346
t.Parallel()
346347
g := NewWithT(t)
347-
_, err := tc.cluster.ValidateUpdate(tc.oldCluster)
348+
_, err := tc.cluster.ValidateUpdate(context.TODO(), nil, tc.oldCluster)
348349
if tc.wantErr {
349350
g.Expect(err).To(HaveOccurred())
350351
} else {

api/v1beta1/azureclusteridentity_webhook_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
2021
"testing"
2122

2223
. "github.com/onsi/gomega"
@@ -83,7 +84,7 @@ func TestAzureClusterIdentity_ValidateCreate(t *testing.T) {
8384
for _, tc := range tests {
8485
t.Run(tc.name, func(t *testing.T) {
8586
g := NewWithT(t)
86-
_, err := tc.clusterIdentity.ValidateCreate()
87+
_, err := tc.clusterIdentity.ValidateCreate(context.TODO(), nil)
8788
if tc.wantErr {
8889
g.Expect(err).To(HaveOccurred())
8990
} else {
@@ -163,7 +164,7 @@ func TestAzureClusterIdentity_ValidateUpdate(t *testing.T) {
163164
for _, tc := range tests {
164165
t.Run(tc.name, func(t *testing.T) {
165166
g := NewWithT(t)
166-
_, err := tc.clusterIdentity.ValidateUpdate(tc.oldClusterIdentity)
167+
_, err := tc.clusterIdentity.ValidateUpdate(context.TODO(), nil, tc.oldClusterIdentity)
167168
if tc.wantErr {
168169
g.Expect(err).To(HaveOccurred())
169170
} else {

api/v1beta1/azureclustertemplate_webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
2021
"testing"
2122

2223
. "github.com/onsi/gomega"
@@ -57,7 +58,7 @@ func TestValidateUpdate(t *testing.T) {
5758

5859
t.Run("template is immutable", func(t *testing.T) {
5960
g := NewWithT(t)
60-
_, err := newClusterTemplate.ValidateUpdate(oldClusterTemplate)
61+
_, err := newClusterTemplate.ValidateUpdate(context.TODO(), nil, oldClusterTemplate)
6162
g.Expect(err).To(HaveOccurred())
6263
})
6364
}

api/v1beta1/azuremanagedcluster_webhook_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"context"
2021
"testing"
2122

2223
. "github.com/onsi/gomega"
@@ -81,7 +82,7 @@ func TestAzureManagedCluster_ValidateUpdate(t *testing.T) {
8182
for _, tc := range tests {
8283
t.Run(tc.name, func(t *testing.T) {
8384
g := NewWithT(t)
84-
_, err := tc.amc.ValidateUpdate(tc.oldAMC)
85+
_, err := tc.amc.ValidateUpdate(context.TODO(), nil, tc.oldAMC)
8586
if tc.wantErr {
8687
g.Expect(err).To(HaveOccurred())
8788
} else {
@@ -124,7 +125,7 @@ func TestAzureManagedCluster_ValidateCreate(t *testing.T) {
124125
for _, tc := range tests {
125126
t.Run(tc.name, func(t *testing.T) {
126127
g := NewWithT(t)
127-
_, err := tc.amc.ValidateCreate()
128+
_, err := tc.amc.ValidateCreate(context.TODO(), nil)
128129
if tc.wantErr {
129130
g.Expect(err).To(HaveOccurred())
130131
} else {
@@ -154,7 +155,7 @@ func TestAzureManagedCluster_ValidateCreateFailure(t *testing.T) {
154155
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, capifeature.MachinePool, *tc.featureGateEnabled)
155156
}
156157
g := NewWithT(t)
157-
_, err := tc.amc.ValidateCreate()
158+
_, err := tc.amc.ValidateCreate(context.TODO(), nil)
158159
if tc.expectError {
159160
g.Expect(err).To(HaveOccurred())
160161
} else {

azure/scope/cluster_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func TestNewClusterScope(t *testing.T) {
103103
},
104104
},
105105
}
106-
azureCluster.Default()
106+
azureCluster.Default(context.TODO(), nil)
107107

108108
fakeIdentity := &infrav1.AzureClusterIdentity{
109109
Spec: infrav1.AzureClusterIdentitySpec{
@@ -230,7 +230,7 @@ func TestAPIServerHost(t *testing.T) {
230230
tc.azureCluster.ObjectMeta = metav1.ObjectMeta{
231231
Name: cluster.Name,
232232
}
233-
tc.azureCluster.Default()
233+
tc.azureCluster.Default(context.TODO(), nil)
234234

235235
clusterScope := &ClusterScope{
236236
Cluster: cluster,
@@ -275,7 +275,7 @@ func TestGettingSecurityRules(t *testing.T) {
275275
},
276276
},
277277
}
278-
azureCluster.Default()
278+
azureCluster.Default(context.TODO(), nil)
279279

280280
clusterScope := &ClusterScope{
281281
Cluster: cluster,
@@ -2161,7 +2161,7 @@ func TestOutboundLBName(t *testing.T) {
21612161
azureCluster.Spec.NetworkSpec.NodeOutboundLB = tc.nodeOutboundLB
21622162
}
21632163

2164-
azureCluster.Default()
2164+
azureCluster.Default(context.TODO(), nil)
21652165

21662166
clusterScope := &ClusterScope{
21672167
AzureCluster: azureCluster,
@@ -2275,7 +2275,7 @@ func TestBackendPoolName(t *testing.T) {
22752275
},
22762276
}
22772277

2278-
azureCluster.Default()
2278+
azureCluster.Default(context.TODO(), nil)
22792279

22802280
if tc.customAPIServerBackendPoolName != "" {
22812281
azureCluster.Spec.NetworkSpec.APIServerLB.BackendPool.Name = tc.customAPIServerBackendPoolName
@@ -2388,7 +2388,7 @@ func TestOutboundPoolName(t *testing.T) {
23882388
}
23892389
}
23902390

2391-
azureCluster.Default()
2391+
azureCluster.Default(context.TODO(), nil)
23922392

23932393
clusterScope := &ClusterScope{
23942394
AzureCluster: azureCluster,

controllers/helpers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ func TestGetCloudProviderConfig(t *testing.T) {
101101

102102
cluster := newCluster("foo")
103103
azureCluster := newAzureCluster("bar")
104-
azureCluster.Default()
104+
azureCluster.Default(context.TODO(), nil)
105105
azureClusterCustomVnet := newAzureClusterWithCustomVnet("bar")
106-
azureClusterCustomVnet.Default()
106+
azureClusterCustomVnet.Default(context.TODO(), nil)
107107

108108
cases := map[string]struct {
109109
cluster *clusterv1.Cluster
@@ -301,7 +301,7 @@ func TestReconcileAzureSecret(t *testing.T) {
301301
cluster := newCluster("foo")
302302
azureCluster := newAzureCluster("bar")
303303

304-
azureCluster.Default()
304+
azureCluster.Default(context.TODO(), nil)
305305
cluster.Name = "testCluster"
306306

307307
fakeIdentity := &infrav1.AzureClusterIdentity{

test/e2e/aks_versions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434

3535
// GetAKSKubernetesVersion gets the kubernetes version for AKS clusters as specified by the environment variable defined by versionVar.
3636
func GetAKSKubernetesVersion(ctx context.Context, e2eConfig *clusterctl.E2EConfig, versionVar string) (string, error) {
37-
e2eAKSVersion := e2eConfig.GetVariable(versionVar)
38-
location := e2eConfig.GetVariable(AzureLocation)
37+
e2eAKSVersion := e2eConfig.GetVariableOrEmpty(versionVar)
38+
location := e2eConfig.GetVariableOrEmpty(AzureLocation)
3939
subscriptionID := getSubscriptionID(Default)
4040

4141
var err error

test/e2e/azure_edgezone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func AzureEdgeZoneClusterSpec(ctx context.Context, inputGetter func() AzureEdgeZ
6969
Expect(err).NotTo(HaveOccurred())
7070

7171
By("Getting extendedLocation Name and Type from environment variables or e2e config file")
72-
extendedLocationType := input.E2EConfig.GetVariable(AzureExtendedLocationType)
73-
extendedLocationName := input.E2EConfig.GetVariable(AzureExtendedLocationName)
72+
extendedLocationType := input.E2EConfig.GetVariableOrEmpty(AzureExtendedLocationType)
73+
extendedLocationName := input.E2EConfig.GetVariableOrEmpty(AzureExtendedLocationName)
7474

7575
cred, err := azidentity.NewDefaultAzureCredential(nil)
7676
Expect(err).NotTo(HaveOccurred())

test/e2e/azure_selfhosted.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
8282
Expect(err).NotTo(HaveOccurred())
8383
clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult)
8484

85-
identityName := input.E2EConfig.GetVariable(ClusterIdentityName)
85+
identityName := input.E2EConfig.GetVariableOrEmpty(ClusterIdentityName)
8686
Expect(os.Setenv(ClusterIdentityName, identityName)).To(Succeed())
8787
Expect(os.Setenv(ClusterIdentityNamespace, namespace.Name)).To(Succeed())
8888
})
@@ -151,22 +151,22 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
151151
err := selfHostedClusterProxy.GetClient().Delete(ctx, &infrav1.AzureClusterIdentity{
152152
ObjectMeta: metav1.ObjectMeta{
153153
Namespace: cluster.Namespace,
154-
Name: e2eConfig.GetVariable(ClusterIdentityName),
154+
Name: e2eConfig.GetVariableOrEmpty(ClusterIdentityName),
155155
},
156156
})
157157
Expect(err).NotTo(HaveOccurred())
158158
cred, err := azidentity.NewDefaultAzureCredential(nil)
159159
Expect(err).NotTo(HaveOccurred())
160160
identityClient, err := armmsi.NewUserAssignedIdentitiesClient(getSubscriptionID(Default), cred, nil)
161161
Expect(err).NotTo(HaveOccurred())
162-
identityRG := e2eConfig.GetVariable(AzureIdentityResourceGroup)
163-
identityName := e2eConfig.GetVariable(AzureUserIdentity)
162+
identityRG := e2eConfig.GetVariableOrEmpty(AzureIdentityResourceGroup)
163+
identityName := e2eConfig.GetVariableOrEmpty(AzureUserIdentity)
164164
identity, err := identityClient.Get(ctx, identityRG, identityName, nil)
165165
Expect(err).NotTo(HaveOccurred())
166166
err = selfHostedClusterProxy.GetClient().Create(ctx, &infrav1.AzureClusterIdentity{
167167
ObjectMeta: metav1.ObjectMeta{
168168
Namespace: cluster.Namespace,
169-
Name: e2eConfig.GetVariable(ClusterIdentityName),
169+
Name: e2eConfig.GetVariableOrEmpty(ClusterIdentityName),
170170
Labels: map[string]string{
171171
clusterctlv1.ClusterctlMoveHierarchyLabel: "true",
172172
},
@@ -175,7 +175,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
175175
AllowedNamespaces: &infrav1.AllowedNamespaces{},
176176
ClientID: *identity.Properties.ClientID,
177177
ResourceID: *identity.ID,
178-
TenantID: e2eConfig.GetVariable(AzureTenantID),
178+
TenantID: e2eConfig.GetVariableOrEmpty(AzureTenantID),
179179
Type: infrav1.UserAssignedMSI,
180180
},
181181
})
@@ -237,22 +237,22 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
237237
err := input.BootstrapClusterProxy.GetClient().Delete(ctx, &infrav1.AzureClusterIdentity{
238238
ObjectMeta: metav1.ObjectMeta{
239239
Namespace: namespace.Name,
240-
Name: e2eConfig.GetVariable(ClusterIdentityName),
240+
Name: e2eConfig.GetVariableOrEmpty(ClusterIdentityName),
241241
},
242242
})
243243
Expect(err).NotTo(HaveOccurred())
244244
err = input.BootstrapClusterProxy.GetClient().Create(ctx, &infrav1.AzureClusterIdentity{
245245
ObjectMeta: metav1.ObjectMeta{
246246
Namespace: namespace.Name,
247-
Name: e2eConfig.GetVariable(ClusterIdentityName),
247+
Name: e2eConfig.GetVariableOrEmpty(ClusterIdentityName),
248248
Labels: map[string]string{
249249
clusterctlv1.ClusterctlMoveHierarchyLabel: "true",
250250
},
251251
},
252252
Spec: infrav1.AzureClusterIdentitySpec{
253253
AllowedNamespaces: &infrav1.AllowedNamespaces{},
254-
ClientID: e2eConfig.GetVariable(AzureClientIDUserAssignedIdentity),
255-
TenantID: e2eConfig.GetVariable(AzureTenantID),
254+
ClientID: e2eConfig.GetVariableOrEmpty(AzureClientIDUserAssignedIdentity),
255+
TenantID: e2eConfig.GetVariableOrEmpty(AzureTenantID),
256256
Type: infrav1.WorkloadIdentity,
257257
},
258258
})

test/e2e/azure_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,23 @@ var _ = Describe("Workload cluster creation", func() {
7878

7979
result = new(clusterctl.ApplyClusterTemplateAndWaitResult)
8080

81-
asoSecretName := e2eConfig.GetVariable("ASO_CREDENTIAL_SECRET_NAME")
81+
asoSecretName := e2eConfig.GetVariableOrEmpty("ASO_CREDENTIAL_SECRET_NAME")
8282
asoSecret := &corev1.Secret{
8383
ObjectMeta: metav1.ObjectMeta{
8484
Namespace: namespace.Name,
8585
Name: asoSecretName,
8686
},
8787
StringData: map[string]string{
88-
config.AzureSubscriptionID: e2eConfig.GetVariable(AzureSubscriptionID),
89-
config.AzureTenantID: e2eConfig.GetVariable(AzureTenantID),
90-
config.AzureClientID: e2eConfig.GetVariable(AzureClientIDUserAssignedIdentity),
91-
config.AuthMode: e2eConfig.GetVariable("ASO_CREDENTIAL_SECRET_MODE"),
88+
config.AzureSubscriptionID: e2eConfig.GetVariableOrEmpty(AzureSubscriptionID),
89+
config.AzureTenantID: e2eConfig.GetVariableOrEmpty(AzureTenantID),
90+
config.AzureClientID: e2eConfig.GetVariableOrEmpty(AzureClientIDUserAssignedIdentity),
91+
config.AuthMode: e2eConfig.GetVariableOrEmpty("ASO_CREDENTIAL_SECRET_MODE"),
9292
},
9393
}
9494
err = bootstrapClusterProxy.GetClient().Create(ctx, asoSecret)
9595
Expect(client.IgnoreAlreadyExists(err)).NotTo(HaveOccurred())
9696

97-
identityName := e2eConfig.GetVariable(ClusterIdentityName)
97+
identityName := e2eConfig.GetVariableOrEmpty(ClusterIdentityName)
9898
Expect(os.Setenv(ClusterIdentityName, identityName)).To(Succeed())
9999
Expect(os.Setenv(ClusterIdentityNamespace, defaultNamespace)).To(Succeed())
100100
additionalCleanup = nil
@@ -300,7 +300,7 @@ var _ = Describe("Workload cluster creation", func() {
300300

301301
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
302302
specName,
303-
withAzureCNIv1Manifest(e2eConfig.GetVariable(AzureCNIv1Manifest)), // AzureCNIManifest is set
303+
withAzureCNIv1Manifest(e2eConfig.GetVariableOrEmpty(AzureCNIv1Manifest)), // AzureCNIManifest is set
304304
withFlavor("azure-cni-v1"),
305305
withNamespace(namespace.Name),
306306
withClusterName(clusterName),
@@ -363,7 +363,7 @@ var _ = Describe("Workload cluster creation", func() {
363363
withFlavor("flatcar"),
364364
withNamespace(namespace.Name),
365365
withClusterName(clusterName),
366-
withKubernetesVersion(e2eConfig.GetVariable(FlatcarKubernetesVersion)),
366+
withKubernetesVersion(e2eConfig.GetVariableOrEmpty(FlatcarKubernetesVersion)),
367367
withControlPlaneMachineCount(1),
368368
withWorkerMachineCount(1),
369369
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
@@ -401,7 +401,7 @@ var _ = Describe("Workload cluster creation", func() {
401401
withFlavor("flatcar-sysext"),
402402
withNamespace(namespace.Name),
403403
withClusterName(clusterName),
404-
withKubernetesVersion(e2eConfig.GetVariable(capi_e2e.KubernetesVersion)),
404+
withKubernetesVersion(e2eConfig.GetVariableOrEmpty(capi_e2e.KubernetesVersion)),
405405
withControlPlaneMachineCount(1),
406406
withWorkerMachineCount(1),
407407
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
@@ -803,7 +803,7 @@ var _ = Describe("Workload cluster creation", func() {
803803
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
804804
specName,
805805
withFlavor("aks"),
806-
withAzureCNIv1Manifest(e2eConfig.GetVariable(AzureCNIv1Manifest)),
806+
withAzureCNIv1Manifest(e2eConfig.GetVariableOrEmpty(AzureCNIv1Manifest)),
807807
withNamespace(namespace.Name),
808808
withClusterName(clusterName),
809809
withKubernetesVersion(kubernetesVersion),

0 commit comments

Comments
 (0)