MCPcopy Create free account
hub / github.com/stretchr/testify / TestErrorAs

Function TestErrorAs

assert/assertions_test.go:3349–3372  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3347}
3348
3349func 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
3374func TestNotErrorAs(t *testing.T) {
3375 tests := []struct {

Callers

nothing calls this directly

Calls 4

FailedMethod · 0.80
ErrorAsFunction · 0.70
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected