diff --git a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go index a843614af..d4a985fdb 100644 --- a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go +++ b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go @@ -5,6 +5,7 @@ package v1alpha1_test import ( "context" + "sync/atomic" "time" . "github.com/onsi/ginkgo/v2" @@ -43,7 +44,7 @@ func intgTestsReconcile() { wcr *vmopv1a1.WebConsoleRequest vm *vmopv1a1.VirtualMachine proxySvc *corev1.Service - v1a2ProviderCalled bool + v1a2ProviderCalled atomic.Bool ) getWebConsoleRequest := func(ctx *builder.IntegrationTestContext, objKey types.NamespacedName) *vmopv1a1.WebConsoleRequest { @@ -99,7 +100,7 @@ func intgTestsReconcile() { intgFakeVMProvider.Lock() intgFakeVMProvider.GetVirtualMachineWebMKSTicketFn = func(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error) { - v1a2ProviderCalled = true + v1a2ProviderCalled.Store(true) return v1a2Ticket, nil } intgFakeVMProvider.Unlock() @@ -109,7 +110,7 @@ func intgTestsReconcile() { ctx.AfterEach() ctx = nil intgFakeVMProvider.Reset() - v1a2ProviderCalled = false + v1a2ProviderCalled.Store(false) }) Context("Reconcile", func() { @@ -147,7 +148,7 @@ func intgTestsReconcile() { g.Expect(wcr.Status.Response).ToNot(BeEmpty()) }).Should(Succeed(), "waiting response to be set") - Expect(v1a2ProviderCalled).Should(BeTrue()) + Expect(v1a2ProviderCalled.Load()).Should(BeTrue()) Expect(wcr.Status.ProxyAddr).To(Equal("192.168.0.1")) Expect(wcr.Status.Response).To(Equal(v1a2Ticket)) Expect(wcr.Status.ExpiryTime.Time).To(BeTemporally("~", time.Now(), webconsolerequest.DefaultExpiryTime)) diff --git a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go index 7a75d87aa..dccf02ca6 100644 --- a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go +++ b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go @@ -1,10 +1,11 @@ -// Copyright (c) 2022 VMware, Inc. All Rights Reserved. +// Copyright (c) 2022-2024 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package v1alpha1_test import ( "context" + "sync/atomic" "time" . "github.com/onsi/ginkgo/v2" @@ -114,7 +115,7 @@ func unitTestsReconcile() { Context("ReconcileNormal", func() { var ( - v1a2ProviderCalled bool + v1a2ProviderCalled atomic.Bool ) BeforeEach(func() { @@ -123,21 +124,21 @@ func unitTestsReconcile() { JustBeforeEach(func() { fakeVMProvider.GetVirtualMachineWebMKSTicketFn = func(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error) { - v1a2ProviderCalled = true + v1a2ProviderCalled.Store(true) return v1a2Ticket, nil } }) AfterEach(func() { fakeVMProvider.Reset() - v1a2ProviderCalled = false + v1a2ProviderCalled.Store(false) }) It("returns success", func() { err := reconciler.ReconcileNormal(wcrCtx) Expect(err).ToNot(HaveOccurred()) - Expect(v1a2ProviderCalled).Should(BeTrue()) + Expect(v1a2ProviderCalled.Load()).Should(BeTrue()) Expect(wcrCtx.WebConsoleRequest.Status.ProxyAddr).To(Equal("dummy-proxy-ip")) Expect(wcrCtx.WebConsoleRequest.Status.Response).To(Equal(v1a2Ticket)) Expect(wcrCtx.WebConsoleRequest.Status.ExpiryTime.Time).To(BeTemporally("~", time.Now(), webconsolerequest.DefaultExpiryTime))