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: Remove the struct type constraint on 'TestEqualExportedValues' to support pointer comparisons #1384

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
8 changes: 0 additions & 8 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,6 @@ func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ..
return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
}

if aType.Kind() != reflect.Struct {
return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
}

if bType.Kind() != reflect.Struct {
return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
}

expected = copyExportedFields(expected)
actual = copyExportedFields(actual)

Expand Down
13 changes: 8 additions & 5 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type S6 struct {
unexported string
}

func TestObjectsExportedFieldsAreEqual(t *testing.T) {
func TestEqualExportedValues(t *testing.T) {

intValue := 1

Expand Down Expand Up @@ -225,6 +225,8 @@ func TestObjectsExportedFieldsAreEqual(t *testing.T) {
{Nested{&intValue, 2}, Nested{&intValue, 2}, true},
{Nested{&Nested{1, 2}, 3}, Nested{&Nested{1, "b"}, 3}, true},
{Nested{&Nested{1, 2}, 3}, Nested{nil, 3}, false},
{&Nested{1, 2}, &Nested{1, "b"}, true},
{&Nested{1, 2}, &Nested{"a", 2}, false},

{
Nested{map[interface{}]*Nested{nil: nil}, 2},
Expand Down Expand Up @@ -254,11 +256,12 @@ func TestObjectsExportedFieldsAreEqual(t *testing.T) {
}

for _, c := range cases {
t.Run(fmt.Sprintf("ObjectsExportedFieldsAreEqual(%#v, %#v)", c.expected, c.actual), func(t *testing.T) {
res := ObjectsExportedFieldsAreEqual(c.expected, c.actual)
t.Run(fmt.Sprintf("EqualExportedValues(%#v, %#v)", c.expected, c.actual), func(t *testing.T) {
mockT := new(testing.T)
res := EqualExportedValues(mockT, c.expected, c.actual)

if res != c.result {
t.Errorf("ObjectsExportedFieldsAreEqual(%#v, %#v) should return %#v", c.expected, c.actual, c.result)
t.Errorf("EqualExportedValues(%#v, %#v) should return %#v", c.expected, c.actual, c.result)
}

})
Expand Down Expand Up @@ -348,7 +351,7 @@ func TestCopyExportedFields(t *testing.T) {
}
}

func TestEqualExportedValues(t *testing.T) {
func TestEqualExportedValuesDiffs(t *testing.T) {
cases := []struct {
value1 interface{}
value2 interface{}
Expand Down