Add mocktest package: Silent TestingT for use inside Eventually#203
Open
lei-wego wants to merge 1 commit into
Open
Add mocktest package: Silent TestingT for use inside Eventually#203lei-wego wants to merge 1 commit into
lei-wego wants to merge 1 commit into
Conversation
…ually testify v1.11.0 changed assert.Eventually to evaluate the condition at t=0 before the first tick (stretchr/testify#1424). Mock assertion helpers (AssertNumberOfCalls, AssertExpectations, AssertCalled, AssertNotCalled) all call t.Errorf on failure — when called from inside Eventually with the real test T, the t=0 evaluation runs before any async goroutine has fired, permanently marking the test failed even if the condition becomes true on a later tick. mocktest.Silent is a mock.TestingT that swallows all calls, letting those helpers be polled safely from Eventually conditions: assert.Eventually(t, func() bool { return m.AssertNumberOfCalls(mocktest.Silent, "Foo", 1) }, waitFor, tick) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Adds a tiny new module `github.com/wego/pkg/mocktest` with a single export — `mocktest.Silent` — a `mock.TestingT` implementation that discards every call. Use it as the `TestingT` argument to testify mock assertion helpers (`AssertNumberOfCalls`, `AssertCalled`, `AssertNotCalled`, `AssertExpectations`) when polling inside `Eventually`.
Why
testify v1.11.0 changed `assert.Eventually` to evaluate the condition at t=0 before the first tick (stretchr/testify#1424). Mock assertion helpers all call `t.Errorf` on failure — so when called inside `Eventually` with the real test `T`, the initial poll (which runs before any async goroutine has had a chance to fire) permanently marks the test failed even when the condition becomes true on a later tick.
`mocktest.Silent` swallows the per-poll failure, letting the helpers be polled safely:
```go
assert.Eventually(t, func() bool {
return m.AssertNumberOfCalls(mocktest.Silent, "Foo", 1)
}, waitFor, tick)
```
Context
`wego/payments` currently works around this with a `replace github.com/stretchr/testify => v1.10.0` directive (added in wego/payments#1951) to keep ~106 legacy call sites green. Once this PR lands and is tagged, payments will adopt `mocktest.Silent`, refactor those sites, and drop the testify pin.
Tests
Run: `cd mocktest && go test -v .` → 5/5 pass.
Test plan
After merge: tag as `mocktest/v0.1.0` so consumers can pin.