Skip to content

Commit e1ee83f

Browse files
committed
Use HaveLen to check length of something
Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
1 parent 9f2186f commit e1ee83f

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

internal/controller/mantlebackup_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ var _ = Describe("import", func() {
22652265
Expect(err).NotTo(HaveOccurred())
22662266
Expect(pv.GetLabels()["app.kubernetes.io/name"]).To(Equal(labelAppNameValue))
22672267
Expect(pv.GetLabels()["app.kubernetes.io/component"]).To(Equal(labelComponentZeroOutVolume))
2268-
Expect(len(pv.Spec.AccessModes)).To(Equal(1))
2268+
Expect(pv.Spec.AccessModes).To(HaveLen(1))
22692269
Expect(pv.Spec.AccessModes[0]).To(Equal(corev1.ReadWriteOnce))
22702270
Expect(pv.Spec.Capacity).To(Equal(pvCapacity))
22712271
Expect(pv.Spec.CSI.Driver).To(Equal(pvDriver))
@@ -2287,7 +2287,7 @@ var _ = Describe("import", func() {
22872287
Expect(pvc.GetLabels()["app.kubernetes.io/name"]).To(Equal(labelAppNameValue))
22882288
Expect(pvc.GetLabels()["app.kubernetes.io/component"]).To(Equal(labelComponentZeroOutVolume))
22892289
Expect(*pvc.Spec.StorageClassName).To(Equal(""))
2290-
Expect(len(pvc.Spec.AccessModes)).To(Equal(1))
2290+
Expect(pvc.Spec.AccessModes).To(HaveLen(1))
22912291
Expect(pvc.Spec.AccessModes[0]).To(Equal(corev1.ReadWriteOnce))
22922292
Expect(pvc.Spec.Resources).To(Equal(pvcResources))
22932293
Expect(*pvc.Spec.VolumeMode).To(Equal(corev1.PersistentVolumeBlock))
@@ -2299,17 +2299,17 @@ var _ = Describe("import", func() {
22992299
Expect(job.GetLabels()["app.kubernetes.io/name"]).To(Equal(labelAppNameValue))
23002300
Expect(job.GetLabels()["app.kubernetes.io/component"]).To(Equal(labelComponentZeroOutJob))
23012301
Expect(*job.Spec.BackoffLimit).To(Equal(int32(65535)))
2302-
Expect(len(job.Spec.Template.Spec.Containers)).To(Equal(1))
2302+
Expect(job.Spec.Template.Spec.Containers).To(HaveLen(1))
23032303
Expect(job.Spec.Template.Spec.Containers[0].Name).To(Equal("zeroout"))
23042304
Expect(*job.Spec.Template.Spec.Containers[0].SecurityContext.Privileged).To(BeTrue())
23052305
Expect(*job.Spec.Template.Spec.Containers[0].SecurityContext.RunAsGroup).To(Equal(int64(0)))
23062306
Expect(*job.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser).To(Equal(int64(0)))
23072307
Expect(job.Spec.Template.Spec.Containers[0].Image).To(Equal(mbr.podImage))
2308-
Expect(len(job.Spec.Template.Spec.Containers[0].VolumeDevices)).To(Equal(1))
2308+
Expect(job.Spec.Template.Spec.Containers[0].VolumeDevices).To(HaveLen(1))
23092309
Expect(job.Spec.Template.Spec.Containers[0].VolumeDevices[0].Name).To(Equal("zeroout-rbd"))
23102310
Expect(job.Spec.Template.Spec.Containers[0].VolumeDevices[0].DevicePath).To(Equal("/dev/zeroout-rbd"))
23112311
Expect(job.Spec.Template.Spec.RestartPolicy).To(Equal(corev1.RestartPolicyOnFailure))
2312-
Expect(len(job.Spec.Template.Spec.Volumes)).To(Equal(1))
2312+
Expect(job.Spec.Template.Spec.Volumes).To(HaveLen(1))
23132313
Expect(job.Spec.Template.Spec.Volumes[0]).To(Equal(corev1.Volume{
23142314
Name: "zeroout-rbd",
23152315
VolumeSource: corev1.VolumeSource{

test/e2e/multik8s/full_backup_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ var _ = Describe("full backup", Label("full-backup"), func() {
132132
// Make sure snapshots are correctly created.
133133
primarySnaps, err := ListRBDSnapshotsInPVC(PrimaryK8sCluster, namespace, pvcName)
134134
Expect(err).NotTo(HaveOccurred())
135-
Expect(len(primarySnaps)).To(Equal(1))
135+
Expect(primarySnaps).To(HaveLen(1))
136136
Expect(primarySnaps[0].Name).To(Equal(backupName))
137137
secondarySnaps, err := ListRBDSnapshotsInPVC(SecondaryK8sCluster, namespace, pvcName)
138138
Expect(err).NotTo(HaveOccurred())
139-
Expect(len(secondarySnaps)).To(Equal(1)) // middle snapshots should be deleted.
139+
Expect(secondarySnaps).To(HaveLen(1)) // Middle snapshots should be deleted.
140140
Expect(secondarySnaps[0].Name).To(Equal(backupName))
141141

142142
By("ensuring the PVC can be attached to the pod in the primary cluster")

test/e2e/multik8s/testutil/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func WriteRandomDataToPV(ctx SpecContext, cluster int, namespace, pvcName string
487487
}).Should(Succeed())
488488
stdout, _, err := Kubectl(cluster, nil, "logs", "-n", namespace, "job/"+writeJobName)
489489
Expect(err).NotTo(HaveOccurred())
490-
Expect(len(stdout)).NotTo(Equal(0))
490+
Expect(stdout).NotTo(HaveLen(0))
491491
return string(stdout)
492492
}
493493

0 commit comments

Comments
 (0)