-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
assert.EqualValuesAbout equalityAbout equalityenhancementpkg-assertChange related to package testify/assertChange related to package testify/assert
Description
Description
EqualExportedValues
does not handle slices for now, although Equal
and EqualValues
compare each element of 2 slices.
Proposed solution
Removing the check that the provided variables are structs or pointers to structs here allows comparing two slices.
Line 629 in 352d243
if aType.Kind() != reflect.Struct { |
Happy to propose a PR if you agree with this design!
I made a PR to remove the described checks.
Use case
The implementation of EqualExportedValues can actually compare slices, if they are inside a struct.
Here is an example.
func TestSomething(t *testing.T) {
type sliceWrapper struct {
ExportedSlice []int
}
a := sliceWrapper{ExportedSlice: []int{1, 2, 3}}
b := sliceWrapper{ExportedSlice: []int{1, 2, 3}}
assert.Equal(t, a.ExportedSlice, b.ExportedSlice) // OK
assert.EqualValues(t, a.ExportedSlice, b.ExportedSlice) // OK
assert.EqualExportedValues(t, a.ExportedSlice, b.ExportedSlice) // Types expected to both be struct or pointer to struct
// Possible workaround: use a struct wrapper.
assert.Equal(t, a, b) // OK
assert.EqualValues(t, a, b) // OK
assert.EqualExportedValues(t, a, b) // OK
}
DamienDelprat, MathiasGr, salvatore-caputi-pixart, HaraldNordgren, mitchlloyd and 3 more
Metadata
Metadata
Assignees
Labels
assert.EqualValuesAbout equalityAbout equalityenhancementpkg-assertChange related to package testify/assertChange related to package testify/assert