From 42d887f28b4602ac3570597162aed14af8f1d909 Mon Sep 17 00:00:00 2001 From: Reda Chlieh Date: Thu, 11 Apr 2024 22:54:14 +0200 Subject: [PATCH] Remove type validation in EqualExportedValues --- assert/assertions.go | 15 ------------ assert/assertions_test.go | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 8109ef2..5a2b29c 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -619,21 +619,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.Ptr { - aType = aType.Elem() - } - if bType.Kind() == reflect.Ptr { - bType = bType.Elem() - } - - if aType.Kind() != reflect.Struct { - return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to 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 or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...) - } - expected = copyExportedFields(expected) actual = copyExportedFields(actual) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 0ae36cd..1bcf53c 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -449,6 +449,56 @@ func TestEqualExportedValues(t *testing.T) { + Exported: (int) 1, notExported: (interface {}) `, }, + { + value1: []int{1, 2}, + value2: []int{1, 2}, + expectedEqual: true, + }, + { + value1: []int{1, 2}, + value2: []int{1, 3}, + expectedEqual: false, + expectedFail: ` + Diff: + --- Expected + +++ Actual + @@ -2,3 +2,3 @@ + (int) 1, + - (int) 2 + + (int) 3 + }`, + }, + { + value1: []*Nested{ + {1, 2}, + {3, 4}, + }, + value2: []*Nested{ + {1, "a"}, + {3, "b"}, + }, + expectedEqual: true, + }, + { + value1: []*Nested{ + {1, 2}, + {3, 4}, + }, + value2: []*Nested{ + {1, "a"}, + {2, "b"}, + }, + expectedEqual: false, + expectedFail: ` + Diff: + --- Expected + +++ Actual + @@ -6,3 +6,3 @@ + (*assert.Nested)({ + - Exported: (int) 3, + + Exported: (int) 2, + notExported: (interface {}) `, + }, } for _, c := range cases {