SubMapOf
func SubMapOf(model any, expectedEntries ...MapEntries) TestDeepSubMapOf operator compares the contents of a map against the non-zero
values of model (if any) and the values of expectedEntries.
model must be the same type as compared data.
expectedEntries can be omitted, if no TestDeep operators are involved. If expectedEntries contains more than one item, all items are merged before their use, from left to right.
During a match, each map entry should be matched by an expected entry to succeed. But some expected entries can be missing from the compared map.
got := map[string]string{
"foo": "test",
"zip": "buzz",
}
td.Cmp(t, got, td.SubMapOf(
map[string]string{
"foo": "test",
"bar": "wizz",
},
td.MapEntries{
"zip": td.HasSuffix("zz"),
}),
) // succeeds
td.Cmp(t, got, td.SubMapOf(
map[string]string{
"bar": "wizz",
},
td.MapEntries{
"zip": td.HasSuffix("zz"),
}),
) // fails, extra {"foo": "test"} in gotTypeBehind method returns the reflect.Type of model.
See also
MapandSuperMapOf.
See also SubMapOf godoc.
Examples
CmpSubMapOf shortcut
func CmpSubMapOf(t TestingT, got, model any, expectedEntries MapEntries, args ...any) boolCmpSubMapOf is a shortcut for:
td.Cmp(t, got, td.SubMapOf(model, expectedEntries), args...)See above for details.
SubMapOf optional parameter expectedEntries is here mandatory.
nil value should be passed to mimic its absence in
original SubMapOf call.
Returns true if the test is OK, false if it fails.
If t is a *T then its Config field is inherited.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
See also CmpSubMapOf godoc.
Examples
T.SubMapOf shortcut
func (t *T) SubMapOf(got, model any, expectedEntries MapEntries, args ...any) boolSubMapOf is a shortcut for:
t.Cmp(got, td.SubMapOf(model, expectedEntries), args...)See above for details.
SubMapOf optional parameter expectedEntries is here mandatory.
nil value should be passed to mimic its absence in
original SubMapOf call.
Returns true if the test is OK, false if it fails.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
See also T.SubMapOf godoc.
Examples