Skip to content

Commit 6efdf2b

Browse files
committed
[-] added test for errors.As
1 parent fc72af5 commit 6efdf2b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

mirror_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package errors
22

33
import (
44
"errors"
5+
"fmt"
56
"testing"
67
)
78

@@ -106,3 +107,17 @@ func TestIs(t *testing.T) {
106107
})
107108
}
108109
}
110+
111+
func TestAs(t *testing.T) {
112+
// ref: https://github.com/golang/go/issues/37625#issuecomment-594045710
113+
err := fmt.Errorf("fmt error")
114+
target := &Error{}
115+
if errors.As(err, &target) {
116+
t.Error("As() = true, want false")
117+
}
118+
119+
err = New("type *Error")
120+
if !errors.As(err, &target) {
121+
t.Error("As() = false, want true")
122+
}
123+
}

0 commit comments

Comments
 (0)