From b935f0aca9e1fa6c8e3d8749f0bfd9a307f9cad7 Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Mon, 1 Jul 2024 18:59:00 +0200 Subject: [PATCH] controllers: add unit test coverage for esxi host label on supervisor --- controllers/vmware/test/controllers_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/controllers/vmware/test/controllers_test.go b/controllers/vmware/test/controllers_test.go index 20dbed8600..da573fcda4 100644 --- a/controllers/vmware/test/controllers_test.go +++ b/controllers/vmware/test/controllers_test.go @@ -45,6 +45,7 @@ import ( vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1" "sigs.k8s.io/cluster-api-provider-vsphere/controllers" vmwarewebhooks "sigs.k8s.io/cluster-api-provider-vsphere/internal/webhooks/vmware" + "sigs.k8s.io/cluster-api-provider-vsphere/pkg/constants" capvcontext "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context" "sigs.k8s.io/cluster-api-provider-vsphere/pkg/manager" ) @@ -672,12 +673,26 @@ var _ = Describe("Reconciliation tests", func() { } newVM.Status.Network.PrimaryIP4 = "1.2.3.4" newVM.Status.BiosUUID = "test-bios-uuid" + newVM.Status.Host = "some-esxi-host" return k8sClient.Status().Update(ctx, newVM) }, time.Second*30).Should(Succeed()) By("Expect the VSphereMachine VM status to reflect VM Ready status") assertEventuallyVMStatus(infraMachineKey, infraMachine, vmwarev1.VirtualMachineStateReady) + By("Expect the Machine's label to reflect the ESXi host") + EventuallyWithOffset(1, func() (string, error) { + if err := k8sClient.Get(ctx, machineKey, machine); err != nil { + return "", err + } + v, ok := machine.GetLabels()[constants.ESXiHostInfoLabel] + if !ok { + return "", fmt.Errorf("expect machine to have label %s", constants.ESXiHostInfoLabel) + } + + return v, nil + }, time.Second*30, time.Millisecond*500).Should(Equal("some-esxi-host")) + // In the case of a LoadBalanced endpoint, ControlPlaneEndpoint is a // load-balancer Testing load-balanced endpoints is done in // control_plane_endpoint_test.go