Skip to content

Commit 4c2ec0f

Browse files
authored
Merge pull request #3475 from Nilesh-chaudhary/resolve-#3432
Add missing tests for azuremachinepool_default.go
2 parents 7af4c11 + 35240f8 commit 4c2ec0f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

exp/api/v1beta1/azuremachinepool_default_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ func TestAzureMachinePool_SetIdentityDefaults(t *testing.T) {
8484
SystemAssignedIdentityRole: &infrav1.SystemAssignedIdentityRole{},
8585
}}}
8686

87+
bothRoleAssignmentNamesPopulatedTest := test{machinePool: &AzureMachinePool{Spec: AzureMachinePoolSpec{
88+
Identity: infrav1.VMIdentitySystemAssigned,
89+
RoleAssignmentName: existingRoleAssignmentName,
90+
SystemAssignedIdentityRole: &infrav1.SystemAssignedIdentityRole{
91+
Name: existingRoleAssignmentName,
92+
},
93+
}}}
94+
95+
bothRoleAssignmentNamesPopulatedTest.machinePool.SetIdentityDefaults(fakeSubscriptionID)
96+
g.Expect(bothRoleAssignmentNamesPopulatedTest.machinePool.Spec.RoleAssignmentName).To(Equal(existingRoleAssignmentName))
97+
g.Expect(bothRoleAssignmentNamesPopulatedTest.machinePool.Spec.SystemAssignedIdentityRole.Name).To(Equal(existingRoleAssignmentName))
98+
8799
roleAssignmentExistTest.machinePool.SetIdentityDefaults(fakeSubscriptionID)
88100
g.Expect(roleAssignmentExistTest.machinePool.Spec.SystemAssignedIdentityRole.Name).To(Equal(existingRoleAssignmentName))
89101

@@ -114,6 +126,10 @@ func TestAzureMachinePool_SetDiagnosticsDefaults(t *testing.T) {
114126
machinePool *AzureMachinePool
115127
}
116128

129+
bootDiagnosticsDefault := &infrav1.BootDiagnostics{
130+
StorageAccountType: infrav1.ManagedDiagnosticsStorage,
131+
}
132+
117133
managedStorageDiagnostics := test{machinePool: &AzureMachinePool{
118134
Spec: AzureMachinePoolSpec{
119135
Template: AzureMachinePoolMachineTemplate{
@@ -161,6 +177,18 @@ func TestAzureMachinePool_SetDiagnosticsDefaults(t *testing.T) {
161177
},
162178
}}
163179

180+
// Test that when no diagnostics are specified, the defaults are set correctly
181+
nilBootDiagnostics := test{machinePool: &AzureMachinePool{
182+
Spec: AzureMachinePoolSpec{
183+
Template: AzureMachinePoolMachineTemplate{
184+
Diagnostics: &infrav1.Diagnostics{},
185+
},
186+
},
187+
}}
188+
189+
nilBootDiagnostics.machinePool.SetDiagnosticsDefaults()
190+
g.Expect(nilBootDiagnostics.machinePool.Spec.Template.Diagnostics.Boot).To(Equal(bootDiagnosticsDefault))
191+
164192
managedStorageDiagnostics.machinePool.SetDiagnosticsDefaults()
165193
g.Expect(managedStorageDiagnostics.machinePool.Spec.Template.Diagnostics.Boot.StorageAccountType).To(Equal(infrav1.ManagedDiagnosticsStorage))
166194

@@ -174,6 +202,45 @@ func TestAzureMachinePool_SetDiagnosticsDefaults(t *testing.T) {
174202
g.Expect(nilDiagnostics.machinePool.Spec.Template.Diagnostics.Boot.StorageAccountType).To(Equal(infrav1.ManagedDiagnosticsStorage))
175203
}
176204

205+
func TestAzureMachinePool_SetSpotEvictionPolicyDefaults(t *testing.T) {
206+
g := NewWithT(t)
207+
208+
type test struct {
209+
machinePool *AzureMachinePool
210+
}
211+
212+
// test to Ensure the the default policy is set to Deallocate if EvictionPolicy is nil
213+
defaultEvictionPolicy := infrav1.SpotEvictionPolicyDeallocate
214+
nilDiffDiskSettingsPolicy := test{machinePool: &AzureMachinePool{
215+
Spec: AzureMachinePoolSpec{
216+
Template: AzureMachinePoolMachineTemplate{
217+
SpotVMOptions: &infrav1.SpotVMOptions{
218+
EvictionPolicy: nil,
219+
},
220+
},
221+
},
222+
}}
223+
nilDiffDiskSettingsPolicy.machinePool.SetSpotEvictionPolicyDefaults()
224+
g.Expect(nilDiffDiskSettingsPolicy.machinePool.Spec.Template.SpotVMOptions.EvictionPolicy).To(Equal(&defaultEvictionPolicy))
225+
226+
// test to Ensure the the default policy is set to Delete if diffDiskSettings option is set to "Local"
227+
expectedEvictionPolicy := infrav1.SpotEvictionPolicyDelete
228+
diffDiskSettingsPolicy := test{machinePool: &AzureMachinePool{
229+
Spec: AzureMachinePoolSpec{
230+
Template: AzureMachinePoolMachineTemplate{
231+
SpotVMOptions: &infrav1.SpotVMOptions{},
232+
OSDisk: infrav1.OSDisk{
233+
DiffDiskSettings: &infrav1.DiffDiskSettings{
234+
Option: "Local",
235+
},
236+
},
237+
},
238+
},
239+
}}
240+
diffDiskSettingsPolicy.machinePool.SetSpotEvictionPolicyDefaults()
241+
g.Expect(diffDiskSettingsPolicy.machinePool.Spec.Template.SpotVMOptions.EvictionPolicy).To(Equal(&expectedEvictionPolicy))
242+
}
243+
177244
func TestAzureMachinePool_SetNetworkInterfacesDefaults(t *testing.T) {
178245
g := NewWithT(t)
179246

0 commit comments

Comments
 (0)