-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
helpers: isError: strict type comparison instead of implementing check (
#97)
- Loading branch information
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
analyzer/testdata/src/error-nil-issue95/mixed_struct_type_test.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package errornilissue95 | ||
|
||
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) | ||
} |
This file contains 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