Hi!
My usecase for this is to have a default matching value for map's key.
tc := map[string][]string{
"test_key": {"aaa"},
"other_key": {},
"ignore": {},
}
Expect(tc).To(HaveKeyWithValue("test_key", "aaa"))
Now, the test case is that, other than test_key, it should be empty or not exists.
if I try something like this Expect(tc).To(HaveKeyWithValue(Not(Equal("test_key")), BeEmpty())), it will not match if there is no other key than the test key.
Currently I'm using this matcher for that case
Expect(tc).To(WithTransform(
func(m map[string]string) map[string]string {
delete(m, "test_key")
return m
},
Or(BeEmpty(), HaveEach(BeEmpty())),
))
Currently, I'm doing this for a composed matcher, so, that solution seems good enough. But I think I'll ask anyway to see if there is anything I miss or that might be a possible improvement.
Thanks!
Hi!
My usecase for this is to have a default matching value for map's key.
Now, the test case is that, other than
test_key, it should be empty or not exists.if I try something like this
Expect(tc).To(HaveKeyWithValue(Not(Equal("test_key")), BeEmpty())), it will not match if there is no other key than the test key.Currently I'm using this matcher for that case
Currently, I'm doing this for a composed matcher, so, that solution seems good enough. But I think I'll ask anyway to see if there is anything I miss or that might be a possible improvement.
Thanks!