Skip to content

Commit

Permalink
tests: use HaveLen(...) and BeEmpty()
Browse files Browse the repository at this point in the history
Replace Expect(len(...)).To(Equal(...))
with Expect(...).To(HaveLen(...)) and Expect(...).To(BeEmpty()) to get
a better info when it fails.

Signed-off-by: Ben Oukhanov <[email protected]>
  • Loading branch information
codingben committed Mar 22, 2022
1 parent d6f82df commit 3e915f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions pkg/monitoring/domainstats/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ = Describe("Collector", func() {

skipped, completed := cc.Collect(vmis, fs, 1*time.Second)

Expect(len(skipped)).To(Equal(0))
Expect(skipped).To(BeEmpty())
Expect(completed).To(BeTrue())
})
})
Expand All @@ -73,7 +73,7 @@ var _ = Describe("Collector", func() {

skipped, completed := cc.Collect(vmis, fs, 1*time.Second)

Expect(len(skipped)).To(Equal(0))
Expect(skipped).To(BeEmpty())
Expect(completed).To(BeFalse())
})

Expand All @@ -85,19 +85,19 @@ var _ = Describe("Collector", func() {
By("Doing a first collection")
skipped, completed := cc.Collect(vmis, fs, 1*time.Second)
// first collection is not aware of the blocked source
Expect(len(skipped)).To(Equal(0))
Expect(skipped).To(BeEmpty())
Expect(completed).To(BeFalse())

By("Doing a second collection")
skipped, completed = cc.Collect(vmis, fs, 1*time.Second)
// second collection is not aware of the blocked source
Expect(len(skipped)).To(Equal(0))
Expect(skipped).To(BeEmpty())
Expect(completed).To(BeFalse())

By("Collecting again with a blocked source")
skipped, completed = cc.Collect(vmis, fs, 1*time.Second)
// second collection is aware of the blocked source
Expect(len(skipped)).To(Equal(1))
Expect(skipped).To(HaveLen(1))
Expect(skipped[0]).To(Equal("a"))
Expect(completed).To(BeTrue())

Expand All @@ -111,13 +111,13 @@ var _ = Describe("Collector", func() {
By("Doing a first collection")
skipped, completed := cc.Collect(vmis, fs, 1*time.Second)
// first collection is not aware of the blocked source
Expect(len(skipped)).To(Equal(0))
Expect(skipped).To(BeEmpty())
Expect(completed).To(BeFalse())

By("Collecting again with a blocked source")
skipped, completed = cc.Collect(vmis, fs, 1*time.Second)
// second collection is aware of the blocked source
Expect(len(skipped)).To(Equal(1))
Expect(skipped).To(HaveLen(1))
Expect(skipped[0]).To(Equal("b"))
Expect(completed).To(BeTrue())

Expand All @@ -128,7 +128,7 @@ var _ = Describe("Collector", func() {

By("Restored a clean state")
skipped, completed = cc.Collect(vmis, fs, 1*time.Second)
Expect(len(skipped)).To(Equal(0))
Expect(skipped).To(BeEmpty())
Expect(completed).To(BeTrue())
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _ = Describe("Hostmetrics", func() {

metrics := hostmetrics.Collect()

Expect(len(metrics)).To(Equal(9))
Expect(metrics).To(HaveLen(9))
Expect(metrics[0].Name).To(Equal("NumberOfPhysicalCPUs"))
Expect(metrics[0].Unit).To(Equal(""))
Expect(metrics[0].Value).To(Equal("3"))
Expand Down Expand Up @@ -58,7 +58,7 @@ var _ = Describe("Hostmetrics", func() {
}

metrics := hostmetrics.Collect()
Expect(len(metrics)).To(Equal(count))
Expect(metrics).To(HaveLen(count))

},
table.Entry("cpuinfo", "nonexistent", "testdata/meminfo", "testdata/stat", "testdata/vmstat", 8),
Expand Down
6 changes: 3 additions & 3 deletions pkg/monitoring/vmistats/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ var _ = Describe("Utility functions", func() {

countMap = makeVMICountMetricMap(nil)
Expect(countMap).NotTo(BeNil())
Expect(len(countMap)).To(Equal(0))
Expect(countMap).To(BeEmpty())

vmis := []*k6tv1.VirtualMachineInstance{}
countMap = makeVMICountMetricMap(vmis)
Expect(countMap).NotTo(BeNil())
Expect(len(countMap)).To(Equal(0))
Expect(countMap).To(BeEmpty())
})

It("should handle different VMI phases", func() {
Expand Down Expand Up @@ -189,7 +189,7 @@ var _ = Describe("Utility functions", func() {

countMap := makeVMICountMetricMap(vmis)
Expect(countMap).NotTo(BeNil())
Expect(len(countMap)).To(Equal(3))
Expect(countMap).To(HaveLen(3))

running := vmiCountMetric{
Phase: "running",
Expand Down

0 comments on commit 3e915f1

Please sign in to comment.