50 Go Testing Mistakes

Hiding surprises in test helpers
Comparing error strings is a bad idea. However, hiding the comparison deep within the comparer function is even worse.
It hides deep the logic responsible for validating functions in tests and can give a false feeling of security.
Let’s find out what’s wrong with the function below and find out how we can improve it.
func errorComparer(e1, e2 error) bool {
if e1 == nil || e2 == nil {
return errors.Is(e1, e2)
}
return e1.Error() == e2.Error()
}
