Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: Fail Subset/NotSubset when a map superset is missing elements #1290

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,10 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
for i := 0; i < len(subsetKeys); i++ {
subsetKey := subsetKeys[i]
subsetElement := subsetValue.MapIndex(subsetKey).Interface()
listElement := listValue.MapIndex(subsetKey).Interface()
listEntry := listValue.MapIndex(subsetKey)

if !ObjectsAreEqual(subsetElement, listElement) {
return Fail(t, fmt.Sprintf("\"%s\" does not contain \"%s\"", list, subsetElement), msgAndArgs...)
if !listEntry.IsValid() || !ObjectsAreEqual(subsetElement, listEntry.Interface()) {
return Fail(t, fmt.Sprintf("%q is a not subset of %q", subset, list), msgAndArgs...)
}
}

Expand Down Expand Up @@ -904,9 +904,9 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
for i := 0; i < len(subsetKeys); i++ {
subsetKey := subsetKeys[i]
subsetElement := subsetValue.MapIndex(subsetKey).Interface()
listElement := listValue.MapIndex(subsetKey).Interface()
listEntry := listValue.MapIndex(subsetKey)

if !ObjectsAreEqual(subsetElement, listElement) {
if !listEntry.IsValid() || !ObjectsAreEqual(subsetElement, listEntry.Interface()) {
return true
}
}
Expand Down
8 changes: 8 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,14 @@ func TestSubsetNotSubset(t *testing.T) {
"a": "x",
"b": "z",
}, false, `{ "a": "x", "b": "y", "c": "z"} does not contain { "a": "x", "b": "z"}`},
{map[string]string{
"a": "x",
"b": "y",
}, map[string]string{
"a": "x",
"b": "y",
"c": "z",
}, false, `{"a": "x", "b": "y"} does not contain {"a": "x", "b": "y", "c": "z"}`},
}

for _, c := range cases {
Expand Down