Skip to content

Commit

Permalink
test: unit test for topolvm node daemonset
Browse files Browse the repository at this point in the history
Verify node daemonset creation and deletion using the controller unit test

Signed-off-by: Juan Miguel Olmo Martínez <[email protected]>
  • Loading branch information
jmolmo committed Dec 16, 2021
1 parent be0d4ed commit 85d9d73
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions controllers/lvmcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
lvmv1alpha1 "github.com/red-hat-storage/lvm-operator/api/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -51,6 +52,10 @@ var _ = Describe("LVMCluster controller", func() {
csiDriverName := types.NamespacedName{Name: TopolvmCSIDriverName}
csiDriverOut := &storagev1.CSIDriver{}

// CSI Node resource
csiNodeName := types.NamespacedName{Namespace: testLvmClusterNamespace, Name: TopolvmNodeDaemonsetName}
csiNodeOut := &appsv1.DaemonSet{}

Context("Reconciliation on creating an LVMCluster CR", func() {
It("should reconcile LVMCluster CR creation, ", func() {
By("verifying CR status.Ready is set to true on reconciliation")
Expand All @@ -65,11 +70,19 @@ var _ = Describe("LVMCluster controller", func() {
return lvmClusterOut.Status.Ready
}, timeout, interval).Should(Equal(true))

// creation of CSI Driver resource
By("confirming presence of CSIDriver resource")
Eventually(func() bool {
err := k8sClient.Get(ctx, csiDriverName, csiDriverOut)
return err == nil
}, timeout, interval).Should(BeTrue())

// creation of CSI Node resource
By("confirming the existence of CSI Node resource")
Eventually(func() bool {
err := k8sClient.Get(ctx, csiNodeName, csiNodeOut)
return err == nil
}, timeout, interval).Should(BeTrue())
})
})

Expand All @@ -89,6 +102,13 @@ var _ = Describe("LVMCluster controller", func() {
return errors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())

// deletion of CSI Node resource
By("confirming absence of CSI Node Resource")
Eventually(func() bool {
err := k8sClient.Get(ctx, csiNodeName, csiNodeOut)
return errors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())

By("confirming absence of LVMCluster CR")
Eventually(func() bool {
err := k8sClient.Get(ctx, lvmClusterName, lvmClusterOut)
Expand Down

0 comments on commit 85d9d73

Please sign in to comment.