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

Function ErrorIs

assert/assertions.go:2092–2111  ·  view source on GitHub ↗

ErrorIs asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.

(t TestingT, err, target error, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

2090// ErrorIs asserts that at least one of the errors in err's chain matches target.
2091// This is a wrapper for errors.Is.
2092func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool {
2093 if h, ok := t.(tHelper); ok {
2094 h.Helper()
2095 }
2096 if errors.Is(err, target) {
2097 return true
2098 }
2099
2100 var expectedText string
2101 if target != nil {
2102 expectedText = target.Error()
2103 }
2104
2105 chain := buildErrorChainString(err)
2106
2107 return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+
2108 "expected: %q\n"+
2109 "in chain: %s", expectedText, chain,
2110 ), msgAndArgs...)
2111}
2112
2113// NotErrorIs asserts that none of the errors in err's chain matches target.
2114// This is a wrapper for errors.Is.

Callers 4

ErrorIsFunction · 0.92
ErrorIsfFunction · 0.70
TestErrorIsFunction · 0.70
ErrorIsMethod · 0.70

Calls 5

buildErrorChainStringFunction · 0.85
IsMethod · 0.80
FailFunction · 0.70
HelperMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestErrorIsFunction · 0.56