Add a haveKeys() helper function to match multiple keys

Signed-off-by: Itamar Holder <iholder@redhat.com>
This commit is contained in:
Itamar Holder 2023-07-19 13:45:58 +03:00
parent 90c362b343
commit 81abfca407

View File

@ -165,3 +165,18 @@ func boundedSample(lower, upper interface{}) types.GomegaMatcher {
"Histogram": gstruct.Ignore(),
}))
}
func haveKeys(keys ...string) types.GomegaMatcher {
gomega.ExpectWithOffset(1, keys).ToNot(gomega.BeEmpty())
matcher := gomega.HaveKey(keys[0])
if len(keys) == 1 {
return matcher
}
for _, key := range keys[1:] {
matcher = gomega.And(matcher, gomega.HaveKey(key))
}
return matcher
}