Skip to content

Commit ce8ff50

Browse files
committed
add unit testing for hostname - 2
1 parent 4d7fa4d commit ce8ff50

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

controllers/cloudstackmachine_controller_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,32 @@ var _ = Describe("CloudStackMachineReconciler", func() {
7272
return false
7373
}, timeout).WithPolling(pollInterval).Should(BeTrue())
7474
})
75+
76+
It("Should replace ds.mete_data.hostname with capi machine name.", func() {
77+
// Mock a call to GetOrCreateVMInstance and set the machine to running.
78+
mockCloudClient.EXPECT().GetOrCreateVMInstance(
79+
gomock.Any(), gomock.Any(), gomock.Any(),
80+
gomock.Any(), gomock.Any(), gomock.Any()).Do(
81+
func(arg1, _, _, _, _, userdata interface{}) {
82+
Ω(userdata == dummies.CAPIMachine.Name).Should(BeTrue())
83+
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
84+
}).AnyTimes()
85+
86+
// Have to do this here or the reconcile call to GetOrCreateVMInstance may happen too early.
87+
setupMachineCRDs()
88+
89+
// Eventually the machine should set ready to true.
90+
Eventually(func() bool {
91+
tempMachine := &infrav1.CloudStackMachine{}
92+
key := client.ObjectKey{Namespace: dummies.ClusterNameSpace, Name: dummies.CSMachine1.Name}
93+
if err := k8sClient.Get(ctx, key, tempMachine); err == nil {
94+
if tempMachine.Status.Ready == true {
95+
return true
96+
}
97+
}
98+
return false
99+
}, timeout).WithPolling(pollInterval).Should(BeTrue())
100+
})
75101
})
76102

77103
Context("With a fake ctrlRuntimeClient and no test Env at all.", func() {

0 commit comments

Comments
 (0)