From 88bab8c18980d917d77ff8c8294c018f2e85b3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20M=C3=B6ller?= Date: Tue, 12 Sep 2023 17:30:23 +0200 Subject: [PATCH] fix: attempt race fix --- pkg/vgmanager/suite_test.go | 18 +++++++----------- pkg/vgmanager/vgmanager_controller_test.go | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pkg/vgmanager/suite_test.go b/pkg/vgmanager/suite_test.go index dcf749380..2bd96a757 100644 --- a/pkg/vgmanager/suite_test.go +++ b/pkg/vgmanager/suite_test.go @@ -44,8 +44,6 @@ import ( lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1" "github.com/openshift/lvm-operator/pkg/filter" - lsblkmocks "github.com/openshift/lvm-operator/pkg/lsblk/mocks" - lvmmocks "github.com/openshift/lvm-operator/pkg/lvm/mocks" "github.com/openshift/lvm-operator/pkg/lvmd" topolvmv1 "github.com/topolvm/topolvm/api/v1" @@ -63,8 +61,7 @@ var ( cancel context.CancelFunc testNodeSelector corev1.NodeSelector testLVMDFile string - mockLSBLK *lsblkmocks.MockLSBLK - mockLVM *lvmmocks.MockLVM + testVGReconciler *VGReconciler ) func TestAPIs(t *testing.T) { @@ -147,20 +144,19 @@ var _ = BeforeSuite(func() { }}} Expect(k8sClient.Create(ctx, testNode)).Should(Succeed()) - testLVMD := lvmd.NewFileConfigurator(filepath.Join(GinkgoT().TempDir(), "lvmd.yaml")) - mockLSBLK = lsblkmocks.NewMockLSBLK(GinkgoT()) - mockLVM = lvmmocks.NewMockLVM(GinkgoT()) - err = (&VGReconciler{ + t := GinkgoT() + testLVMDFile = filepath.Join(t.TempDir(), "lvmd.yaml") + testLVMD := lvmd.NewFileConfigurator(testLVMDFile) + testVGReconciler = &VGReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), EventRecorder: k8sManager.GetEventRecorderFor(ControllerName), - LVM: mockLVM, - LSBLK: mockLSBLK, LVMD: testLVMD, Namespace: testNamespaceName, NodeName: testNodeName, Filters: filter.DefaultFilters, - }).SetupWithManager(k8sManager) + } + err = (testVGReconciler).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) go func() { diff --git a/pkg/vgmanager/vgmanager_controller_test.go b/pkg/vgmanager/vgmanager_controller_test.go index fd30fb078..81dce2c15 100644 --- a/pkg/vgmanager/vgmanager_controller_test.go +++ b/pkg/vgmanager/vgmanager_controller_test.go @@ -10,7 +10,9 @@ import ( . "github.com/onsi/gomega" lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1" "github.com/openshift/lvm-operator/pkg/lsblk" + lsblkmocks "github.com/openshift/lvm-operator/pkg/lsblk/mocks" "github.com/openshift/lvm-operator/pkg/lvm" + lvmmocks "github.com/openshift/lvm-operator/pkg/lvm/mocks" "github.com/stretchr/testify/mock" "k8s.io/apimachinery/pkg/api/errors" "sigs.k8s.io/controller-runtime/pkg/client" @@ -25,9 +27,17 @@ var _ = Describe("vgmanager controller", func() { }) func testMockedBlockDeviceOnHost(ctx context.Context) { + By("injecting mocked LVM and LSBLK") + t := GinkgoT() + mockLSBLK := lsblkmocks.NewMockLSBLK(t) + mockLVM := lvmmocks.NewMockLVM(t) + testVGReconciler.LSBLK = mockLSBLK + testVGReconciler.LVM = mockLVM DeferCleanup(func() { - mockLVM.AssertExpectations(GinkgoT()) - mockLSBLK.AssertExpectations(GinkgoT()) + mockLVM.AssertExpectations(t) + mockLSBLK.AssertExpectations(t) + testVGReconciler.LSBLK = nil + testVGReconciler.LVM = nil }) By("setting up the disk as a block device with losetup")