Closed pohly closed 4 months ago
The reason for using HaveExactElements
instead of BeEmpty
is that the set of expected elements is dynamic.
yes looks like a bug to me. i'll try to prioritize this and get to it soon. i'm a bit behind on ginkgo/gomega stuff these days.
Might be worth checking whether ConsistOf has the same problem.
ConsistOf works:
go test .
--- FAIL: TestHaveExactElements (0.00s)
foo_test.go:13:
Expected
<[]string | len:1, cap:1>: ["test"]
to consist of
<[]interface {} | len:0, cap:0>: []
the extra elements were
<[]string | len:1, cap:1>: ["test"]
FAIL
FAIL k8s.io/kubernetes/foo 0.006s
FAIL
BeEmpty produces better output:
go test .
--- FAIL: TestHaveExactElements (0.00s)
foo_test.go:13:
Expected
<[]string | len:1, cap:1>: ["test"]
to be empty
FAIL
FAIL k8s.io/kubernetes/foo 0.006s
FAIL
alrighty i've fixed this now. will cut a release once CI goes green.
@bart0sh found the following odd behavior:
Output:
I think this is a bug.
HaveExactElements
should report all extra elements in the actual slice. So if there is nothing to match against, any non-empty slice should cause a failure.