testifylint icon indicating copy to clipboard operation
testifylint copied to clipboard

autofixing assert.True -> assert.GreaterOrEqual can break working tests

Open Danlock opened this issue 2 months ago • 0 comments

Running the autofix via golangci-lint will convert this code:

elapsed := time.Minute
assert.True(t, elapsed.Seconds() >= 1)

into this code.

elapsed := time.Minute
assert.GreaterOrEqual(t, elapsed.Seconds(), 1)

However this "fix" introduces a testify error Elements should be the same type. I think this particular category of fixes should be removed as it can break working tests.

A working implementation of this fix would have to analyze the return value of function's passed into testify compare functions and emit code such as assert.GreaterOrEqual(t, elapsed.Seconds(), float64(1)).

Danlock avatar Oct 09 '25 20:10 Danlock