proposal: assert.MapSubset (or just support maps in assert.Subset)
or perhaps expand subset so it can also handle maps.
given
a := map[string]string{
"one": "foo",
"two": "bar",
"three": "baz",
}
b := map[string]string{
"one": "foo",
"three": "baz",
}
c := map[string]string{
"one": "foo",
"three": "notbaz",
}
assert.MapSubset(t, a, b, "a does not contain b") // will pass
assert.MapSubset(t, b, a, "b does not contain a") // will fail b does not have two=bar
assert.MapSubset(t, a, c, "a does not contain c") // will fail a does not have three=notbaz
Enhancing Subset would definitely be better IMO.
One question, should this assert true?
a := map[string]string{
"one": "foo",
"two": "bar",
}
b := map[string]string{
"one": "baz",
}
assert.Subset(t, a, b)
Does it test that the key and value are in the superset, or does it follow two value dereference (_, ok := a["one"]) which only checks the key? It would need to be documented.
it should test both the key and the value.
@brackendawson What is the process to having this proposal accepted? If accepted @SleepyBrett can I work on it?
That would be open a pull request and then hope a maintainer returns.
@brackendawson sure thanks, would create a PR.
Hello @brackendawson @SleepyBrett I created a PR for this issue here: https://github.com/stretchr/testify/pull/1178
FYI testify Contains on Map type validates by map keys, not entries.
While looking for this exact functionality I came across this ticket and #704 which looks like a duplicate.