Improve tests for ErrorIs/ErrorAs

Checks that the assertion result matches what's set in `testing.T`.
pull/1129/head
Pal Sivertsen 2021-11-30 14:29:39 +01:00 committed by Pål Sivertsen
parent 3380867632
commit aade8450b3
1 changed files with 4 additions and 1 deletions

View File

@ -3269,7 +3269,6 @@ func TestNotErrorIs(t *testing.T) {
}
func TestErrorAs(t *testing.T) {
mockT := new(testing.T)
tests := []struct {
err error
result bool
@ -3282,10 +3281,14 @@ func TestErrorAs(t *testing.T) {
tt := tt
var target *customError
t.Run(fmt.Sprintf("ErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) {
mockT := new(testing.T)
res := ErrorAs(mockT, tt.err, &target)
if res != tt.result {
t.Errorf("ErrorAs(%#v,%#v) should return %t", tt.err, target, tt.result)
}
if res == mockT.Failed() {
t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !mockT.Failed())
}
})
}
}