MCPcopy Create free account
hub / github.com/stretchr/testify / EqualExportedValues

Function EqualExportedValues

assert/assertions.go:626–650  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

624// assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
625// assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false
626func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
627 if h, ok := t.(tHelper); ok {
628 h.Helper()
629 }
630
631 aType := reflect.TypeOf(expected)
632 bType := reflect.TypeOf(actual)
633
634 if aType != bType {
635 return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
636 }
637
638 expected = copyExportedFields(expected)
639 actual = copyExportedFields(actual)
640
641 if !ObjectsAreEqualValues(expected, actual) {
642 diff := diff(expected, actual)
643 expected, actual = formatUnequalValues(expected, actual)
644 return Fail(t, fmt.Sprintf("Not equal (comparing only exported fields): \n"+
645 "expected: %s\n"+
646 "actual : %s%s", expected, actual, diff), msgAndArgs...)
647 }
648
649 return true
650}
651
652// Exactly asserts that two objects are equal in value and type.
653//

Callers 4

EqualExportedValuesFunction · 0.92
EqualExportedValuesfFunction · 0.70
TestEqualExportedValuesFunction · 0.70
EqualExportedValuesMethod · 0.70

Calls 6

copyExportedFieldsFunction · 0.85
ObjectsAreEqualValuesFunction · 0.85
formatUnequalValuesFunction · 0.85
FailFunction · 0.70
diffFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestEqualExportedValuesFunction · 0.56