-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_test.go
92 lines (87 loc) · 1.8 KB
/
format_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package berr
import (
"errors"
"fmt"
"strings"
"github.com/stretchr/testify/assert"
)
var (
simpleError = errors.New("simple error")
complexError = fmt.Errorf("complex error: %w", simpleError)
veryComplexError = fmt.Errorf("very complex error: %w", complexError)
ultraComplexError = fmt.Errorf("ultra complex error: %w", veryComplexError)
godLikeComplexError = fmt.Errorf("god like complex error: %w", ultraComplexError)
)
func (suite *betterErrorsTestSuite) TestFormat() {
cases := []struct {
name string
args error
want string
}{
{"simple error", simpleError, "simple error"},
{
"nested in two levels",
complexError,
strings.Join([]string{
"complex error",
"",
"caused by:",
" 0: simple error",
}, "\n"),
},
{
"nested in three levels",
veryComplexError,
strings.Join([]string{
"very complex error",
"",
"caused by:",
" 0: complex error",
" 1: simple error",
}, "\n"),
},
{
"nested in four levels",
ultraComplexError,
strings.Join([]string{
"ultra complex error",
"",
"caused by:",
" 0: very complex error",
" 1: complex error",
" 2: simple error",
}, "\n"),
},
{
"nested in five levels",
godLikeComplexError,
strings.Join([]string{
"god like complex error",
"",
"caused by:",
" 0: ultra complex error",
" 1: very complex error",
" 2: complex error",
" 3: simple error",
}, "\n"),
},
{
"join errors",
errors.Join(simpleError, complexError),
strings.Join([]string{
"simple error",
"",
"complex error",
"",
"caused by:",
" 0: simple error",
}, "\n"),
},
}
for _, c := range cases {
out := Format(c.args)
suite.Run(c.name, func() {
assert.Equal(suite.T(), c.want, out)
})
}
}