-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors_go1.20_test.go
39 lines (34 loc) · 1.06 KB
/
errors_go1.20_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//go:build go1.20
// +build go1.20
package errors
import (
"io"
"testing"
)
func TestJoin(t *testing.T) {
err1 := io.EOF
err2 := io.ErrUnexpectedEOF
err := Join(err1, err2)
innerErr, ok := err.(interface{ Unwrap() []error })
if !ok {
t.Fatalf("expected Join to return an error that implements Unwrap() []error")
}
errs := innerErr.Unwrap()
if len(errs) != 2 {
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return 2 errors")
}
if !Is(errs[0], io.EOF) {
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return io.EOF")
}
if !Is(errs[1], io.ErrUnexpectedEOF) {
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return io.ErrUnexpectedEOF")
}
// test wrapping and then unwrapping with Chain
err = Wrap(err, "my test wrapped error")
if !Is(err, io.EOF) {
t.Fatalf("expected wrapped error to traverse into joined inner error EOF")
}
if !Is(err, io.ErrUnexpectedEOF) {
t.Fatalf("expected wrapped error to traverse into joined inner error ErrUnexpectedEOF")
}
}