Skip to content

Commit

Permalink
fix: attempt race fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Sep 12, 2023
1 parent 99c6473 commit 88bab8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
18 changes: 7 additions & 11 deletions pkg/vgmanager/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
14 changes: 12 additions & 2 deletions pkg/vgmanager/vgmanager_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down

0 comments on commit 88bab8c

Please sign in to comment.