-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
68 lines (58 loc) · 1.37 KB
/
errors_test.go
File metadata and controls
68 lines (58 loc) · 1.37 KB
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
package errors_test
import (
e "errors"
"testing"
errors "github.com/ditointernet/go-dito-errors"
)
func TestSeverity(t *testing.T) {
tt := []struct {
name string
err error
expected errors.ErrorSeverity
}{
{
name: "it should return a default severity if the error isn't a domain error",
err: e.New("mock error"),
expected: errors.SeverityError,
},
{
name: "it should return the error severity",
err: errors.New("mock error", errors.SeverityCritical),
expected: errors.SeverityCritical,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
res := errors.Severity(tc.err)
if res != tc.expected {
t.Errorf("it should return '%d', got '%d'", tc.expected, res)
}
})
}
}
func TestKind(t *testing.T) {
tt := []struct {
name string
err error
expected errors.ErrorKind
}{
{
name: "it should return a default kind if the error isn't a domain error",
err: e.New("mock error"),
expected: errors.KindUnexpected,
},
{
name: "it should return the error kind",
err: errors.New("mock error", errors.KindBadRequest),
expected: errors.KindBadRequest,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
res := errors.Kind(tc.err)
if res != tc.expected {
t.Errorf("it should return '%d', got '%d'", tc.expected, res)
}
})
}
}