Closed ldez closed 6 months ago
$ golangci-lint run -E testifylint main_test.go:32:2: error-nil: use assert.NoError (testifylint) assert.Nil(t, resp) ^
The example is a fake API client.
package main import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // APIResponse can be an error or not. type APIResponse struct { Status int Data string ErrorMsg string } func (a APIResponse) Error() string { return a.ErrorMsg } func Update(a string) (*APIResponse, error) { if a == "a" { return &APIResponse{Status: 200, Data: "fake"}, nil } return nil, &APIResponse{Status: 500, ErrorMsg: "Oops"} } func TestName(t *testing.T) { resp, err := Update("b") require.Error(t, err, new(*APIResponse)) assert.Nil(t, resp) }
@ldez hi!
thank you for request.
the checker intentionally reacts on everything “that satisfies the error interface”, but I think it needs to be changed to the strict “has type error” 👌
error
The example is a fake API client.