EqualExportedValues asserts that the types of two objects are equal and their public fields are also equal. This is useful for comparing structs that have private fields that could potentially differ. type S struct { Exported int notExported int } assert.EqualExportedValues(t, S{1
(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})
| 658 | // assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true |
| 659 | // assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false |
| 660 | func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { |
| 661 | if h, ok := t.(tHelper); ok { |
| 662 | h.Helper() |
| 663 | } |
| 664 | |
| 665 | aType := reflect.TypeOf(expected) |
| 666 | bType := reflect.TypeOf(actual) |
| 667 | |
| 668 | if aType != bType { |
| 669 | return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...) |
| 670 | } |
| 671 | |
| 672 | expected = copyExportedFields(expected) |
| 673 | actual = copyExportedFields(actual) |
| 674 | |
| 675 | if !ObjectsAreEqualValues(expected, actual) { |
| 676 | diff := diff(expected, actual) |
| 677 | expected, actual = formatUnequalValues(expected, actual) |
| 678 | return Fail(t, fmt.Sprintf("Not equal (comparing only exported fields): \n"+ |
| 679 | "expected: %s\n"+ |
| 680 | "actual : %s%s", expected, actual, diff), msgAndArgs...) |
| 681 | } |
| 682 | |
| 683 | return true |
| 684 | } |
| 685 | |
| 686 | // Exactly asserts that two objects are equal in value and type. |
| 687 | // |