-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Problem:
Currently when asserting a specific enum value is set I have been using either assert.Equal(t, val1, val1) or assert.Equal(t, val1.String(), val2.String()).
The first is, imo, better from the point of view of correctness but the second one produces better error messages. I know that I could implement GoString() but that has several problems.
- It seems like changing code for an implementation detail in my testing package.
- Some of the enums I am checking are defined in my dependencies which are out of my control, so I can't even define
GoString()even if I wanted to.
Proposal:
Add the following functions in both testify/assert and testify/require:
func EqualEnum(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
...
}
func EqualEnumf(t *testing.T, expected interface{}, actual interface{}, msg string, args ...interface{}) {
...
}
func NotEqualEnum(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
...
}
func NotEqualEnumf(t *testing.T, expected interface{}, actual interface{}, msg string, args ...interface{}) {
...
}These functions would act very similarly to Equal currently, but in the error output formatting would use the String() function ("%v") not the GoString() function.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels