You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
funcTestSomething(t*testing.T) {
typesliceWrapperstruct {
ExportedSlice []int
}
a:=sliceWrapper{ExportedSlice: []int{1, 2, 3}}
b:=sliceWrapper{ExportedSlice: []int{1, 2, 3}}
assert.Equal(t, a.ExportedSlice, b.ExportedSlice) // OKassert.EqualValues(t, a.ExportedSlice, b.ExportedSlice) // OKassert.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) // OKassert.EqualValues(t, a, b) // OKassert.EqualExportedValues(t, a, b) // OK
}
The text was updated successfully, but these errors were encountered:
But I think it's also a pity that you have to use a slice wrapper when testing a function that returns a slice.
Especially when it's a slice of proto messages, which with the latest code generation have unexported fields.
Another option is to add a new function, but I'm not sure it's the best thing to do.
Or we just accept using a slice wrapper is enough.
For me it's key that the doc says "objects", which is not defined in the go spec, and not "structs". I think this leaves scope for nested structs (already supported) and structs nested in other container types.
Description
EqualExportedValues
does not handle slices for now, althoughEqual
andEqualValues
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.
testify/assert/assertions.go
Line 629 in 352d243
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.
The text was updated successfully, but these errors were encountered: