Skip to content

Commit

Permalink
Support pointer on top-level for 'TestEqualExportedValues' & Get rid …
Browse files Browse the repository at this point in the history
…of duplicate 'ObjectsExportedFieldsAreEqual'
  • Loading branch information
HaraldNordgren committed Oct 16, 2023
1 parent 4ae48e9 commit f952a8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
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

0 comments on commit f952a8a

Please sign in to comment.