all: replace reflect.DeepEqual for error comparisons in test files #71197
Open
Description
Proposal Details
Description
Currently, several test files across the codebase use reflect.DeepEqual
to compare errors. This is not the recommended way to compare errors in Go, as it can be both inefficient and potentially fragile. We should replace these comparisons with proper error comparison methods.
Affected Files
At least the following:
src/strconv/atof_test.go
src/strconv/atoi_test.go
src/errors/join_test.go
src/fmt/errors_test.go
src/net/iprawsock_test.go
src/net/mac_test.go
src/net/tcpsock_test.go
src/net/udpsock_test.go
src/encoding/asn1/asn1_test.go
src/encoding/base64/base64_test.go
src/go/build/build_test.go
Proposed Solution
Replace reflect.DeepEqual
error comparisons with either:
- Direct error string comparison using
err.Error()
for simple cases - Custom error comparison functions that handle nil cases and string comparison
- Use of
errors.Is()
where appropriate
Implementation Plan
The changes will be submitted as separate PRs grouped by package to make reviews more manageable.
Each PR will:
- Remove usage of
reflect.DeepEqual
for error comparisons - Add appropriate error comparison functions where needed
- Maintain existing test coverage and functionality
- Include only the changes related to error comparison
Benefits
- More idiomatic error comparison in tests
- More maintainable and clearer error comparison logic