Skip to content

Commit fc375ce

Browse files
committed
🌱 Fix hbmm delete unit tests.
Before the test did not realy test something because the state is none at the beginning (before provisioning), too.
1 parent cacf064 commit fc375ce

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

controllers/hetznerbaremetalmachine_controller_test.go

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,71 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() {
390390
})
391391

392392
It("deletes successfully", func() {
393-
By("deleting bm machine")
393+
By("Waiting until host is provisioned")
394+
395+
Eventually(func() bool {
396+
return isPresentAndTrue(key, bmMachine, infrav1.HostReadyCondition)
397+
}, timeout).Should(BeTrue())
398+
399+
err := testEnv.Get(ctx, hostKey, host)
400+
Expect(err).To(BeNil())
401+
402+
Expect(host.Spec.Status.ProvisioningState).To(Equal(infrav1.StateProvisioned))
403+
404+
By("deleting hbmm")
405+
Expect(testEnv.Delete(ctx, bmMachine)).To(Succeed())
406+
407+
Eventually(func() bool {
408+
if err := testEnv.Get(ctx, key, bmMachine); apierrors.IsNotFound(err) {
409+
return true
410+
}
411+
return false
412+
}, timeout, time.Second).Should(BeTrue())
413+
414+
By("making sure the host has been deprovisioned")
394415

416+
Eventually(func() bool {
417+
if err := testEnv.Get(ctx, hostKey, host); err != nil {
418+
return false
419+
}
420+
return host.Spec.Status.ProvisioningState == infrav1.StateNone
421+
}, timeout, time.Second).Should(BeTrue())
422+
})
423+
424+
It("deletes successfully, even if state is 'ensure-provisioned'", func() {
425+
By("checking that the host is ready")
426+
Eventually(func() bool {
427+
return isPresentAndTrue(key, bmMachine, infrav1.HostReadyCondition)
428+
}, timeout).Should(BeTrue())
429+
430+
osSSHClient.On("GetHostName").Return(sshclient.Output{
431+
StdOut: "some-unexpected-hostname",
432+
StdErr: "",
433+
Err: nil,
434+
})
435+
436+
err := testEnv.Get(ctx, hostKey, host)
437+
Expect(err).To(BeNil())
438+
Expect(host.Spec.Status.ProvisioningState).To(Equal(infrav1.StateProvisioned))
439+
440+
By("Setting State to 'ensure-provisioned'")
441+
host.Spec.Status.ProvisioningState = infrav1.StateEnsureProvisioned
442+
err = testEnv.Update(ctx, host)
443+
Expect(err).To(BeNil())
444+
445+
Eventually(func() error {
446+
err := testEnv.Get(ctx, hostKey, host)
447+
apierrors.IsNotFound(err)
448+
if err != nil {
449+
return err
450+
}
451+
if host.Spec.Status.ProvisioningState != infrav1.StateEnsureProvisioned {
452+
return fmt.Errorf("ProvisioningState=%s", host.Spec.Status.ProvisioningState)
453+
}
454+
return nil
455+
}, timeout, time.Second).Should(Succeed())
456+
457+
By("deleting bm machine")
395458
Expect(testEnv.Delete(ctx, bmMachine)).To(Succeed())
396459

397460
Eventually(func() bool {

0 commit comments

Comments
 (0)