Skip to content

Commit

Permalink
lint(ginkgolinter): expect (not)to HaveOccurred
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Mar 28, 2024
1 parent d640cc1 commit e853187
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 54 deletions.
2 changes: 0 additions & 2 deletions golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ issues:
linters:
- dupword
- errcheck
- ginkgolinter
- goconst
- gosec
- govet
Expand All @@ -373,7 +372,6 @@ issues:
- goconst
- gosec
- gosimple
- ginkgolinter
- nilerr
- noctx
- staticcheck
Expand Down
4 changes: 2 additions & 2 deletions internal/storage/storagelocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func TestListBackupStorageLocations(t *testing.T) {
client := fake.NewClientBuilder().WithScheme(util.VeleroScheme).WithRuntimeObjects(tt.backupLocations).Build()
if tt.expectError {
_, err := ListBackupStorageLocations(context.Background(), client, "ns-1")
g.Expect(err).NotTo(BeNil())
g.Expect(err).To(HaveOccurred())
} else {
_, err := ListBackupStorageLocations(context.Background(), client, "ns-1")
g.Expect(err).To(BeNil())
g.Expect(err).ToNot(HaveOccurred())
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/backup_storage_location_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ var _ = Describe("Backup Storage Location Reconciler", func() {
NamespacedName: types.NamespacedName{Namespace: location.Namespace, Name: location.Name},
})
Expect(actualResult).To(BeEquivalentTo(ctrl.Result{}))
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

key := client.ObjectKey{Name: location.Name, Namespace: location.Namespace}
instance := &velerov1api.BackupStorageLocation{}
err = r.client.Get(ctx, key, instance)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(instance.Spec.Default).To(BeIdenticalTo(tests[i].expectedIsDefault))
Expect(instance.Status.Phase).To(BeIdenticalTo(tests[i].expectedPhase))
}
Expand Down Expand Up @@ -165,12 +165,12 @@ var _ = Describe("Backup Storage Location Reconciler", func() {
NamespacedName: types.NamespacedName{Namespace: location.Namespace, Name: location.Name},
})
Expect(actualResult).To(BeEquivalentTo(ctrl.Result{}))
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

key := client.ObjectKey{Name: location.Name, Namespace: location.Namespace}
instance := &velerov1api.BackupStorageLocation{}
err = r.client.Get(ctx, key, instance)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(instance.Spec.Default).To(BeIdenticalTo(tests[i].expectedIsDefault))
}
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/backup_sync_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ var _ = Describe("Backup Sync Reconciler", func() {
})

Expect(actualResult).To(BeEquivalentTo(ctrl.Result{}))
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

// process the cloud backups
for _, cloudBackupData := range test.cloudBackups {
Expand All @@ -467,7 +467,7 @@ var _ = Describe("Backup Sync Reconciler", func() {
cloudBackupData.backup.Status.Expiration.After(fakeClock.Now())) {
Expect(apierrors.IsNotFound(err)).To(BeTrue())
} else {
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

// did this cloud backup already exist in the cluster?
var existing *velerov1api.Backup
Expand Down Expand Up @@ -496,7 +496,7 @@ var _ = Describe("Backup Sync Reconciler", func() {
locationName = label.GetValidName(locationName)
}
Expect(locationName).To(BeEquivalentTo(obj.Labels[velerov1api.StorageLocationLabel]))
Expect(len(obj.Labels[velerov1api.StorageLocationLabel]) <= validation.DNS1035LabelMaxLength).To(BeTrue())
Expect(len(obj.Labels[velerov1api.StorageLocationLabel])).To(BeNumerically("<=", validation.DNS1035LabelMaxLength))
}
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/download_request_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var _ = Describe("Download Request Reconciler", func() {
// now will be used to set the fake clock's time; capture
// it here so it can be referenced in the test case defs.
now, err := time.Parse(time.RFC1123, time.RFC1123)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
now = now.Local()

rClock := testclocks.NewFakeClock(now)
Expand All @@ -86,22 +86,22 @@ var _ = Describe("Download Request Reconciler", func() {

fakeClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
err = fakeClient.Create(context.TODO(), test.downloadRequest)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

if test.backup != nil {
err := fakeClient.Create(context.TODO(), test.backup)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
}

if test.backupLocation != nil {
err := fakeClient.Create(context.TODO(), test.backupLocation)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
backupStores[test.backupLocation.Name] = &persistencemocks.BackupStore{}
}

if test.restore != nil {
err := fakeClient.Create(context.TODO(), test.restore)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
}

// Setup reconciler
Expand Down Expand Up @@ -129,7 +129,7 @@ var _ = Describe("Download Request Reconciler", func() {

Expect(actualResult).To(BeEquivalentTo(test.expectedRequeue))
if test.expectedReconcileErr == "" {
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
} else {
Expect(err.Error()).To(Equal(test.expectedReconcileErr))
}
Expand All @@ -146,7 +146,7 @@ var _ = Describe("Download Request Reconciler", func() {
} else {
Expect(instance.Status).ToNot(Equal(test.downloadRequest.Status))
}
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
}

if test.expectGetsURL {
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/pod_volume_backup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() {
// `now` will be used to set the fake clock's time; capture
// it here so it can be referenced in the test case defs.
now, err := time.Parse(time.RFC1123, time.RFC1123)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
now = now.Local()

DescribeTable("a pod volume backup",
Expand All @@ -150,21 +150,21 @@ var _ = Describe("PodVolumeBackup Reconciler", func() {

fakeClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
err = fakeClient.Create(ctx, test.pvb)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

err = fakeClient.Create(ctx, test.pod)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

err = fakeClient.Create(ctx, test.bsl)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

err = fakeClient.Create(ctx, test.backupRepo)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

fakeFS := velerotest.NewFakeFileSystem()
pathGlob := fmt.Sprintf("/host_pods/%s/volumes/*/%s", "", "pvb-1-volume")
_, err = fakeFS.Create(pathGlob)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

credentialFileStore, err := credentials.NewNamespacedFileStore(
fakeClient,
Expand All @@ -173,7 +173,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() {
fakeFS,
)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

if test.dataMgr == nil {
test.dataMgr = datapath.NewManager(1)
Expand Down Expand Up @@ -208,7 +208,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() {
})
Expect(actualResult).To(BeEquivalentTo(test.expectedRequeue))
if test.expectedErrMsg == "" {
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
} else {
Expect(err.Error()).To(BeEquivalentTo(test.expectedErrMsg))
}
Expand All @@ -222,7 +222,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() {
if test.expected == nil {
Expect(apierrors.IsNotFound(err)).To(BeTrue())
} else {
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Eventually(pvb.Status.Phase).Should(Equal(test.expected.Status.Phase))
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/server_status_request_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = Describe("Server Status Request Reconciler", func() {
// `now` will be used to set the fake clock's time; capture
// it here so it can be referenced in the test case defs.
now, err := time.Parse(time.RFC1123, time.RFC1123)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
now = now.Local()

DescribeTable("a Server Status request",
Expand All @@ -79,7 +79,7 @@ var _ = Describe("Server Status Request Reconciler", func() {

Expect(actualResult).To(BeEquivalentTo(test.expectedRequeue))
if test.expectedErrMsg == "" {
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
} else {
Expect(err.Error()).To(BeEquivalentTo(test.expectedErrMsg))
return
Expand All @@ -92,7 +92,7 @@ var _ = Describe("Server Status Request Reconciler", func() {
if test.expected == nil {
Expect(apierrors.IsNotFound(err)).To(BeTrue())
} else {
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Eventually(instance.Status.Phase == test.expected.Status.Phase, timeout).Should(BeTrue())
}
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestDeleteOldMaintenanceJobs(t *testing.T) {
assert.NoError(t, err)

// We expect the number of jobs to be equal to 'keep'
assert.Equal(t, keep, len(jobList.Items))
assert.Len(t, jobList.Items, keep)

// We expect that the oldest jobs were deleted
// Job3 should not be present in the remaining list
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/api-group/enable_api_group_extentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func APIExtensionsVersionsTest() {
Skip("CRD with apiextension versions dstVersions should have v1")
return ""
})
Expect(len(srcVersions) > 1 && len(dstVersions) == 1).Should(Equal(true), func() string {
Expect(len(srcVersions) > 1 && len(dstVersions) == 1).Should(BeTrue(), func() string {
Skip("Source cluster should support apiextension v1 and v1beta1, destination cluster should only support apiextension v1")
return ""
})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/basic/backup-volume-info/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (v *BackupVolumeInfo) CreateResources() error {
fmt.Printf("Creating deployment in namespaces ...%s\n", createNSName)
// Make sure PVC count is great than 3 to allow both empty volumes and file populated volumes exist per pod
pvcCount := 4
Expect(pvcCount > 3).To(Equal(true))
Expect(pvcCount).To(BeNumerically(">", 3))

var vols []*v1.Volume
for i := 0; i <= pvcCount-1; i++ {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/basic/nodeport.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (n *NodePort) CreateResources() error {
Expect(createServiceWithNodeport(n.Ctx, n.Client, ns, n.serviceName, n.labels, 0)).To(Succeed(), fmt.Sprintf("Failed to create service %s", n.serviceName))
service, err := GetService(n.Ctx, n.Client, ns, n.serviceName)
Expect(err).To(Succeed())
Expect(len(service.Spec.Ports)).To(Equal(1))
Expect(service.Spec.Ports).To(HaveLen(1))
n.nodePort = service.Spec.Ports[0].NodePort
_, err = GetAllService(n.Ctx)
Expect(err).To(Succeed(), "fail to get service")
Expand Down Expand Up @@ -135,7 +135,7 @@ func (n *NodePort) Restore() error {
By(fmt.Sprintf("Delete service %s by deleting namespace %s", n.serviceName, ns), func() {
service, err := GetService(n.Ctx, n.Client, ns, n.serviceName)
Expect(err).To(Succeed())
Expect(len(service.Spec.Ports)).To(Equal(1))
Expect(service.Spec.Ports).To(HaveLen(1))
fmt.Println(service.Spec.Ports)
Expect(DeleteNamespace(n.Ctx, n.Client, ns, true)).To(Succeed())
})
Expand All @@ -159,7 +159,7 @@ func (n *NodePort) Restore() error {
By(fmt.Sprintf("Verify service %s was restore successfully with the origin nodeport.", ns), func() {
service, err := GetService(n.Ctx, n.Client, ns, n.serviceName)
Expect(err).To(Succeed())
Expect(len(service.Spec.Ports)).To(Equal(1))
Expect(service.Spec.Ports).To(HaveLen(1))
Expect(service.Spec.Ports[0].NodePort).To(Equal(n.nodePort))
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/basic/pvc-selected-node-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *PVCSelectedNodeChanging) CreateResources() error {
By("Prepare ConfigMap data", func() {
nodeNameList, err := GetWorkerNodes(p.Ctx)
Expect(err).To(Succeed())
Expect(len(nodeNameList) >= 2).To(Equal(true))
Expect(len(nodeNameList)).To(BeNumerically(">=", 2))
for _, nodeName := range nodeNameList {
if nodeName != p.oldNodeName {
p.newNodeName = nodeName
Expand Down Expand Up @@ -142,7 +142,7 @@ func (p *PVCSelectedNodeChanging) Verify() error {
By(fmt.Sprintf("PVC selected node should be %s", p.newNodeName), func() {
pvcNameList, err := GetPvcByPVCName(p.Ctx, p.mappedNS, p.pvcName)
Expect(err).To(Succeed())
Expect(len(pvcNameList)).Should(Equal(1))
Expect(pvcNameList).Should(HaveLen(1))
pvc, err := GetPVC(p.Ctx, p.Client, p.mappedNS, pvcNameList[0])
Expect(err).To(Succeed())
Expect(pvc.Annotations[p.ann]).To(Equal(p.newNodeName))
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/bsl-mgmt/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ func BslDeletionTest(useVolumeSnapshots bool) {
pvc, err := GetPvcByPVCName(context.Background(), bslDeletionTestNs, podName_1)
Expect(err).To(Succeed())
fmt.Println(pvc)
Expect(len(pvc)).To(Equal(1))
Expect(pvc).To(HaveLen(1))
pvc1 := pvc[0]
pvc, err = GetPvcByPVCName(context.Background(), bslDeletionTestNs, podName_2)
Expect(err).To(Succeed())
fmt.Println(pvc)
Expect(len(pvc)).To(Equal(1))
Expect(pvc).To(HaveLen(1))
pvc2 := pvc[0]
Expect(AddLabelToPvc(context.Background(), pvc1, bslDeletionTestNs, label_1)).To(Succeed())
Expect(AddLabelToPvc(context.Background(), pvc2, bslDeletionTestNs, label_2)).To(Succeed())
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/privilegesmgmt/ssr.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ func SSRTest() {
By(fmt.Sprintf("Check ssr object in %s namespace", testNS))
Expect(veleroCfg.ClientToInstallVelero.Kubebuilder.List(ctx, ssrListResp, &kbclient.ListOptions{Namespace: testNS})).To(Succeed(),
fmt.Sprintf("Failed to list ssr object in %s namespace", testNS))
Expect(len(ssrListResp.Items)).To(BeNumerically("==", 1),
fmt.Sprintf("Count of ssr object in %s namespace is not 1 but %d", testNS, len(ssrListResp.Items)))
Expect(ssrListResp.Items).To(HaveLen(1), fmt.Sprintf("Count of ssr object in %s namespace is not 1 but %d", testNS, len(ssrListResp.Items)))
Expect(ssrListResp.Items[0].Status.Phase).To(BeEmpty(),
fmt.Sprintf("Status of ssr object in %s namespace should be empty", testNS))
Expect(ssrListResp.Items[0].Status.ServerVersion).To(BeEmpty(),
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/resource-filtering/exclude_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (e *ExcludeFromBackup) Verify() error {
//Check namespace
checkNS, err := GetNamespace(e.Ctx, e.Client, namespace)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Could not retrieve test namespace %s", namespace))
Expect(checkNS.Name == namespace).To(Equal(true), fmt.Sprintf("Retrieved namespace for %s has name %s instead", namespace, checkNS.Name))
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)
Expand All @@ -143,7 +143,7 @@ func (e *ExcludeFromBackup) Verify() error {
//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(apierrors.IsNotFound(err)).To(Equal(true))
Expect(apierrors.IsNotFound(err)).To(BeTrue())

//Check configmap: should be included
_, err = GetConfigmap(e.Client.ClientGo, namespace, e.CaseBaseName)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/resourcemodifiers/resource_modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *ResourceModifiersCase) Verify() error {
for _, ns := range *r.NSIncluded {
By("Verify deployment has updated values", func() {
deploy, err := GetDeployment(r.Client.ClientGo, ns, r.CaseBaseName)
Expect(err).To(BeNil(), fmt.Sprintf("Failed to get deployment %s in namespace %s", r.CaseBaseName, ns))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Failed to get deployment %s in namespace %s", r.CaseBaseName, ns))

Expect(*deploy.Spec.Replicas).To(Equal(int32(2)), fmt.Sprintf("Failed to verify deployment %s's replicas in namespace %s", r.CaseBaseName, ns))
Expect(deploy.Spec.Template.Spec.Containers[1].Image).To(Equal("nginx:1.14.2"), fmt.Sprintf("Failed to verify deployment %s's image in namespace %s", r.CaseBaseName, ns))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/resourcepolicies/resource_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *ResourcePoliciesCase) Verify() error {
content = strings.Replace(content, "\n", "", -1)
originContent := strings.Replace(fmt.Sprintf("ns-%s pod-%s volume-%s", ns, pod.Name, vol.Name), "\n", "", -1)

Expect(content == originContent).To(BeTrue(), fmt.Sprintf("File %s does not exist in volume %s of pod %s in namespace %s",
Expect(content).To(Equal(originContent), fmt.Sprintf("File %s does not exist in volume %s of pod %s in namespace %s",
FileName, vol.Name, pod.Name, ns))
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/schedule/schedule-backup-creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (n *ScheduleBackupCreation) Init() error {
"--include-namespaces", n.namespace,
"--schedule=*/" + fmt.Sprintf("%v", n.Period) + " * * * *",
}
Expect(n.Period < 30).To(Equal(true))
Expect(n.Period).To(BeNumerically("<", 30))
return nil
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func (n *ScheduleBackupCreation) Backup() error {
bMap := make(map[string]string)
backupsInfo, err := GetScheduledBackupsCreationTime(n.Ctx, n.VeleroCfg.VeleroCLI, "default", n.ScheduleName)
Expect(err).To(Succeed())
Expect(len(backupsInfo) == i).To(Equal(true))
Expect(backupsInfo).To(HaveLen(i))
for index, bi := range backupsInfo {
bList := strings.Split(bi, ",")
fmt.Printf("Backup %d: %v\n", index, bList)
Expand Down
Loading

0 comments on commit e853187

Please sign in to comment.