Skip to content

Commit

Permalink
chore: fix unstable UT in storageprovider_controller_test.go (#8397)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjx20 authored Nov 5, 2024
1 parent 5fdffaf commit 25b5850
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 9 additions & 9 deletions controllers/dataprotection/storageprovider_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ var _ = Describe("StorageProvider controller", func() {
g.ExpectWithOffset(1, val).Should(BeTrue())
}

reconcileNoError := func() {
reconcileNoError := func(g Gomega) {
_, err := reconclier.Reconcile(testCtx.Ctx, reconcile.Request{NamespacedName: key})
Expect(err).ToNot(HaveOccurred())
g.ExpectWithOffset(1, err).ToNot(HaveOccurred())
}

It("should reconcile a StorageProvider to Ready status if it doesn't specify csiDriverName", func() {
Expand All @@ -143,7 +143,7 @@ var _ = Describe("StorageProvider controller", func() {

By("checking status.phase and status.conditions")
Eventually(func(g Gomega) {
reconcileNoError()
reconcileNoError(g)
shouldReady(g, getProvider(g))
}).Should(Succeed())
})
Expand All @@ -155,7 +155,7 @@ var _ = Describe("StorageProvider controller", func() {

By("checking status.phase and status.conditions")
Eventually(func(g Gomega) {
reconcileNoError()
reconcileNoError(g)
provider := getProvider(g)
g.Expect(provider.Status.Phase).Should(BeEquivalentTo(dpv1alpha1.StorageProviderReady))

Expand All @@ -170,23 +170,23 @@ var _ = Describe("StorageProvider controller", func() {
createStorageProviderSpec("csi2")
By("checking status.phase, it should be NotReady because CSI driver is not installed yet")
Eventually(func(g Gomega) {
reconcileNoError()
reconcileNoError(g)
shouldNotReady(g, getProvider(g))
}).Should(Succeed())

By("creating CSI driver object csi2")
createCSIDriverObjectSpec("csi2")
By("checking status.phase, it should become Ready")
Eventually(func(g Gomega) {
reconcileNoError()
reconcileNoError(g)
shouldReady(g, getProvider(g))
}).Should(Succeed())

By("deleting CSI driver object csi2")
deleteCSIDriverObject("csi2")
By("checking status.phase, it should become NotReady")
Eventually(func(g Gomega) {
reconcileNoError()
reconcileNoError(g)
shouldNotReady(g, getProvider(g))
}).Should(Succeed())
})
Expand All @@ -197,13 +197,13 @@ var _ = Describe("StorageProvider controller", func() {

By("checking StorageProvider object")
Eventually(testapps.CheckObj(&testCtx, key, func(g Gomega, provider *dpv1alpha1.StorageProvider) {
reconcileNoError()
reconcileNoError(g)
g.Expect(provider.GetFinalizers()).To(ContainElement(dptypes.DataProtectionFinalizerName))
})).Should(Succeed())

By("deleting StorageProvider object")
Eventually(func(g Gomega) {
reconcileNoError()
reconcileNoError(g)
provider := &dpv1alpha1.StorageProvider{}
err := testCtx.Cli.Get(ctx, key, provider)
if apierrors.IsNotFound(err) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/testutil/apps/common_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package apps

import (
"encoding/json"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -333,7 +334,8 @@ func ClearResourcesWithRemoveFinalizerOption[T intctrlutil.Object, PT intctrluti
for _, obj := range items {
pobj := PT(&obj)
if pobj.GetDeletionTimestamp().IsZero() {
panic("expected DeletionTimestamp is not nil")
d, _ := json.Marshal(pobj)
panic("expected DeletionTimestamp is not nil, obj: " + string(d))
}
finalizers := pobj.GetFinalizers()
if len(finalizers) > 0 {
Expand Down

0 comments on commit 25b5850

Please sign in to comment.