test: resolve remaining Ginkgo V2 and Gomega anti-patterns (#10440)

- Replaced Expect().Should() and Expect().ShouldNot() with .To() and .ToNot() across 12 files (Task 1).
- Replaced synchronously evaluated Eventually() with Expect() in server_status_request_controller_test.go (Task 2B).
- Extracted Skip() calls inside lazy callbacks into conditional checks using slices.Contains() in enable_api_group_extentions.go (Task 3).

Signed-off-by: opbot_xd <awasthikrishna23052005@gmail.com>
This commit is contained in:
opbot_xd
2026-09-01 06:43:04 +05:30
parent 3d50723567
commit a607892eb0
12 changed files with 41 additions and 44 deletions
@@ -19,6 +19,7 @@ package basic
import (
"context"
"fmt"
"slices"
"time"
. "github.com/onsi/ginkgo/v2"
@@ -45,26 +46,22 @@ func APIExtensionsVersionsTest() {
veleroCfg = VeleroCfg
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
srcVersions, err := GetAPIVersions(veleroCfg.DefaultClient, resourceName)
Expect(err).ShouldNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())
dstVersions, err := GetAPIVersions(veleroCfg.StandbyClient, resourceName)
Expect(err).ShouldNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())
Expect(srcVersions).Should(ContainElement("v1"), func() string {
if !slices.Contains(srcVersions, "v1") {
Skip("CRD with apiextension versions srcVersions should have v1")
return ""
})
Expect(srcVersions).Should(ContainElement("v1beta1"), func() string {
Skip("CRD with apiextension versions srcVersions should have v1")
return ""
})
Expect(dstVersions).Should(ContainElement("v1"), func() string {
}
if !slices.Contains(srcVersions, "v1beta1") {
Skip("CRD with apiextension versions srcVersions should have v1beta1")
}
if !slices.Contains(dstVersions, "v1") {
Skip("CRD with apiextension versions dstVersions should have v1")
return ""
})
Expect(len(srcVersions) > 1 && len(dstVersions) == 1).Should(BeTrue(), func() string {
}
if !(len(srcVersions) > 1 && len(dstVersions) == 1) {
Skip("Source cluster should support apiextension v1 and v1beta1, destination cluster should only support apiextension v1")
return ""
})
}
})
AfterEach(func() {
By(fmt.Sprintf("Switch to default kubeconfig context %s", veleroCfg.DefaultClusterContext), func() {
@@ -55,7 +55,7 @@ func (c *CSIDataMoverVolumeInfo) Verify() error {
BackupObjectsPrefix+"/"+c.BackupName,
)
Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
Expect(err).ToNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(volumeInfo).ToNot(BeEmpty())
@@ -54,7 +54,7 @@ func (c *CSISnapshotVolumeInfo) Verify() error {
BackupObjectsPrefix+"/"+c.BackupName,
)
Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
Expect(err).ToNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(volumeInfo).ToNot(BeEmpty())
@@ -54,7 +54,7 @@ func (f *FilesystemUploadVolumeInfo) Verify() error {
BackupObjectsPrefix+"/"+f.BackupName,
)
Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
Expect(err).ToNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(volumeInfo).ToNot(BeEmpty())
@@ -55,7 +55,7 @@ func (n *NativeSnapshotVolumeInfo) Verify() error {
BackupObjectsPrefix+"/"+n.BackupName,
)
Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
Expect(err).ToNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(volumeInfo).ToNot(BeEmpty())
@@ -54,7 +54,7 @@ func (s *SkippedVolumeInfo) Verify() error {
BackupObjectsPrefix+"/"+s.BackupName,
)
Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
Expect(err).ToNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.")
fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(volumeInfo).ToNot(BeEmpty())
+2 -2
View File
@@ -308,7 +308,7 @@ func BslDeletionTest(useVolumeSnapshots bool) {
By(fmt.Sprintf("Get all backups from 2 BSLs %s before deleting one of them", backupLocation1), func() {
backupsBeforeDel, err := GetAllBackups(context.Background(), veleroCfg.VeleroCLI)
Expect(err).To(Succeed())
Expect(cmp.Diff(backupsInBsl1AndBsl2, backupsBeforeDel, cmpopts.SortSlices(less))).Should(BeEmpty())
Expect(cmp.Diff(backupsInBsl1AndBsl2, backupsBeforeDel, cmpopts.SortSlices(less))).To(BeEmpty())
By(fmt.Sprintf("Backup1 %s should exist in cloud object store before bsl deletion", backupName1), func() {
Expect(ObjectsShouldBeInBucket(veleroCfg.ObjectStoreProvider, veleroCfg.CloudCredentialsFile,
@@ -325,7 +325,7 @@ func BslDeletionTest(useVolumeSnapshots bool) {
backupsAfterDel, err := GetAllBackups(context.Background(), veleroCfg.VeleroCLI)
Expect(err).To(Succeed())
// Default BSL is deleted, so backups in additional BSL should be left only
Expect(cmp.Diff(backupsInBSL2, backupsAfterDel, cmpopts.SortSlices(less))).Should(BeEmpty())
Expect(cmp.Diff(backupsInBSL2, backupsAfterDel, cmpopts.SortSlices(less))).To(BeEmpty())
})
})
+5 -5
View File
@@ -127,7 +127,7 @@ func (e *ExcludeFromBackup) CreateResources() error {
}
By(fmt.Sprintf("Checking secret %s should exists in namespaces ...%s\n", secretName, namespace), func() {
_, err = GetSecret(e.Client.ClientGo, namespace, e.CaseBaseName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace))
})
//Create Configmap: to be included
configmaptName := e.CaseBaseName
@@ -148,21 +148,21 @@ func (e *ExcludeFromBackup) Verify() error {
By(fmt.Sprintf("Checking resources in namespaces ...%s\n", namespace), func() {
//Check namespace
checkNS, err := GetNamespace(e.Ctx, e.Client, namespace)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Could not retrieve test namespace %s", namespace))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Could not retrieve test namespace %s", namespace))
Expect(checkNS.Name).To(Equal(namespace), fmt.Sprintf("Retrieved namespace for %s has name %s instead", namespace, checkNS.Name))
//Check deployment: should be included
_, err = GetDeployment(e.Client.ClientGo, namespace, e.CaseBaseName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace))
//Check secrets: secrets should not be included
_, err = GetSecret(e.Client.ClientGo, namespace, e.CaseBaseName)
Expect(err).Should(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace))
Expect(err).To(HaveOccurred(), fmt.Sprintf("failed to list deployment in namespace: %q", namespace))
Expect(apierrors.IsNotFound(err)).To(BeTrue())
//Check configmap: should be included
_, err = GetConfigMap(e.Client.ClientGo, namespace, e.CaseBaseName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to list configmap in namespace: %q", namespace))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to list configmap in namespace: %q", namespace))
})
return nil
}
+1 -1
View File
@@ -170,7 +170,7 @@ func (s *InProgressCase) Backup() error {
}
// There should be at most one in-progress backup per schedule.
Expect(inProgressBackupCount).Should(BeNumerically("<=", 1))
Expect(inProgressBackupCount).To(BeNumerically("<=", 1))
// Already ensured at most one in-progress backup when schedule triggered 2 backups.
// Succeed.
+1 -1
View File
@@ -184,7 +184,7 @@ func (n *PeriodicalCase) Verify() error {
By("Namespaces were restored", func() {
for _, ns := range *n.NSIncluded {
_, err := k8sutil.GetConfigMap(n.Client.ClientGo, ns, n.CaseBaseName)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to list CM in namespace: %s\n", ns))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to list CM in namespace: %s\n", ns))
}
})
return nil