MCPcopy
hub / github.com/stretchr/testify / TestErrorAs

Function TestErrorAs

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

Source from the content-addressed store, hash-verified

3832}
3833
3834func TestErrorAs(t *testing.T) {
3835 t.Parallel()
3836
3837 tests := []struct {
3838 err error
3839 result bool
3840 resultErrMsg string
3841 }{
3842 {
3843 err: fmt.Errorf("wrap: %w", &customError{}),
3844 result: true,
3845 },
3846 {
3847 err: io.EOF,
3848 result: false,
3849 resultErrMsg: "" +
3850 "Should be in error chain:\n" +
3851 "expected: *assert.customError\n" +
3852 "in chain: \"EOF\" (*errors.errorString)\n",
3853 },
3854 {
3855 err: nil,
3856 result: false,
3857 resultErrMsg: "" +
3858 "An error is expected but got nil.\n" +
3859 `expected: *assert.customError` + "\n",
3860 },
3861 {
3862 err: fmt.Errorf("abc: %w", errors.New("def")),
3863 result: false,
3864 resultErrMsg: "" +
3865 "Should be in error chain:\n" +
3866 "expected: *assert.customError\n" +
3867 "in chain: \"abc: def\" (*fmt.wrapError)\n" +
3868 "\t\"def\" (*errors.errorString)\n",
3869 },
3870 }
3871 for _, tt := range tests {
3872 tt := tt
3873 var target *customError
3874 t.Run(fmt.Sprintf("ErrorAs(%#v,%#v)", tt.err, target), func(t *testing.T) {
3875 mockT := new(captureTestingT)
3876 res := ErrorAs(mockT, tt.err, &target)
3877 mockT.checkResultAndErrMsg(t, tt.result, res, tt.resultErrMsg)
3878 })
3879 }
3880}
3881
3882func TestNotErrorAs(t *testing.T) {
3883 t.Parallel()

Callers

nothing calls this directly

Calls 4

checkResultAndErrMsgMethod · 0.80
ErrorAsFunction · 0.70
ErrorfMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected