Skip to content

testify: fix assertion anti-patterns, promote require.NoError, expand JSONEq#6471

Merged
lpcox merged 2 commits into
mainfrom
copilot/go-fan-go-module-review-stretchr-testify
May 25, 2026
Merged

testify: fix assertion anti-patterns, promote require.NoError, expand JSONEq#6471
lpcox merged 2 commits into
mainfrom
copilot/go-fan-go-module-review-stretchr-testify

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 25, 2026

Addresses the Go Fan report for stretchr/testify by 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 diff
  • response_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 cast

require.NoError promotion

  • rate_limit_test.go: assert.NoErrorrequire.NoError after strconv.Atoi(retryAfter). On parse failure secs is 0, so the subsequent assert.Greater(t, secs, 0) also fails — cascading noise that require eliminates.

JSONEq expansion

Three pilots replacing assert.Equal with assert.JSONEq on JSON string comparisons, making tests robust to key ordering and whitespace:

// Before
assert.Equal(t, `{"title":"new issue"}`, receivedBody)
assert.Equal(t, `{"ok":true}`, w.Body.String(), "response body should be preserved")
assert.Equal(t, "{}", result)

// After
assert.JSONEq(t, `{"title":"new issue"}`, receivedBody)
assert.JSONEq(t, `{"ok":true}`, w.Body.String(), "response body should be preserved")
assert.JSONEq(t, "{}", result)

Copilot AI linked an issue May 25, 2026 that may be closed by this pull request
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
Copilot AI requested a review from lpcox May 25, 2026 14:21
Copilot finished work on behalf of lpcox May 25, 2026 14:21
@lpcox lpcox marked this pull request as ready for review May 25, 2026 14:25
Copilot AI review requested due to automatic review settings May 25, 2026 14:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.JSONEq for order/whitespace-insensitive comparisons.
  • Replaced generic equality assertions with more semantically correct assertions (assert.Zero, assert.False).
  • Promoted assert.NoError to require.NoError where 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go-fan] Go Module Review: stretchr/testify

3 participants