-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathjoin_test.go
50 lines (48 loc) · 1.27 KB
/
join_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
40
41
42
43
44
45
46
47
48
49
50
package errors
import (
"fmt"
"testing"
)
func TestJoin(t *testing.T) {
t.Run("nil", func(t *testing.T) {
err := Join(nil, nil, nil)
if err != nil {
t.Errorf("expected nil, got %v", err)
}
})
t.Run("one err", func(t *testing.T) {
expected := fmt.Errorf("fake")
err := Join(nil, expected, nil)
je := err.(*joinError)
un := je.Unwrap()
if len(un) != 1 {
t.Fatalf("expected 1 err, got %d", len(un))
}
if s := un[0].Error(); s != expected.Error() {
t.Errorf("expected %v, got %v", expected, un[0])
}
if s := err.Error(); s != expected.Error() {
t.Errorf("expected %s, got %s", expected, err)
}
})
t.Run("many errs", func(t *testing.T) {
expected1 := fmt.Errorf("fake 1")
expected2 := fmt.Errorf("fake 2")
err := Join(nil, expected1, nil, nil, expected2, nil)
je := err.(*joinError)
un := je.Unwrap()
if len(un) != 2 {
t.Fatalf("expected 2 err, got %d", len(un))
}
if s := un[0].Error(); s != expected1.Error() {
t.Errorf("expected %v, got %v", expected1, un[0])
}
if s := un[1].Error(); s != expected2.Error() {
t.Errorf("expected %v, got %v", expected2, un[1])
}
expectedS := expected1.Error() + "\n" + expected2.Error()
if s := err.Error(); s != expectedS {
t.Errorf("expected %s, got %s", expectedS, err)
}
})
}