testify: fix assertion anti-patterns, promote require.NoError, expand JSONEq#6471
Merged
Merged
Conversation
5 tasks
Copilot
AI
changed the title
[WIP] Review go module stretchr/testify for best practices
testify: fix assertion anti-patterns, promote require.NoError, expand JSONEq
May 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Go tests across the codebase to follow stretchr/testify best practices by replacing assertion anti-patterns with more appropriate helpers (Zero, False, JSONEq) and promoting require.NoError where a failure should halt the test to avoid cascading assertions.
Changes:
- Replaced brittle JSON string equality assertions with
assert.JSONEqfor order/whitespace-insensitive comparisons. - Replaced generic equality assertions with more semantically correct assertions (
assert.Zero,assert.False). - Promoted
assert.NoErrortorequire.NoErrorwhere subsequent assertions depend on successful parsing.
Show a summary per file
| File | Description |
|---|---|
| internal/server/http_helpers_test.go | Uses assert.JSONEq for response body JSON comparison in header-preservation test. |
| internal/proxy/response_transform_coverage_test.go | Replaces boolean equality comparison with assert.False on a typed value. |
| internal/proxy/rate_limit_test.go | Switches to require.NoError after strconv.Atoi to prevent cascading failures. |
| internal/proxy/handler_test.go | Uses assert.JSONEq for request body JSON comparison in passthrough test. |
| internal/oidc/jwt_expiry_test.go | Replaces assert.Equal(..., 0, ...) with assert.Zero for clearer intent/failure output. |
| internal/logger/sanitize/sanitize_test.go | Uses assert.JSONEq for empty-object JSON output comparison. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 0
This was referenced May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the Go Fan report for
stretchr/testifyby applying the identified quick wins and best-practice improvements across test files.Anti-pattern fixes
jwt_expiry_test.go:assert.Equal(t, 0, len(rawPayload)%4)→assert.Zero(t, len(rawPayload)%4)— produces a meaningful "expected zero value" failure message instead of a generic diffresponse_transform_coverage_test.go:assert.Equal(t, false, m["incomplete_results"])→assert.False(t, m["incomplete_results"].(bool))— uses the correct boolean assertion with an explicit type castrequire.NoError promotion
rate_limit_test.go:assert.NoError→require.NoErrorafterstrconv.Atoi(retryAfter). On parse failuresecsis 0, so the subsequentassert.Greater(t, secs, 0)also fails — cascading noise thatrequireeliminates.JSONEq expansion
Three pilots replacing
assert.Equalwithassert.JSONEqon JSON string comparisons, making tests robust to key ordering and whitespace: