| 3347 | } |
| 3348 | |
| 3349 | func TestErrorAs(t *testing.T) { |
| 3350 | tests := []struct { |
| 3351 | err error |
| 3352 | result bool |
| 3353 | }{ |
| 3354 | {fmt.Errorf("wrap: %w", &customError{}), true}, |
| 3355 | {io.EOF, false}, |
| 3356 | {nil, false}, |
| 3357 | } |
| 3358 | for _, tt := range tests { |
| 3359 | tt := tt |
| 3360 | var target *customError |
| 3361 | t.Run(fmt.Sprintf("ErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) { |
| 3362 | mockT := new(testing.T) |
| 3363 | res := ErrorAs(mockT, tt.err, &target) |
| 3364 | if res != tt.result { |
| 3365 | t.Errorf("ErrorAs(%#v,%#v) should return %t", tt.err, target, tt.result) |
| 3366 | } |
| 3367 | if res == mockT.Failed() { |
| 3368 | t.Errorf("The test result (%t) should be reflected in the testing.T type (%t)", res, !mockT.Failed()) |
| 3369 | } |
| 3370 | }) |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | func TestNotErrorAs(t *testing.T) { |
| 3375 | tests := []struct { |