-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherr_details_test.go
64 lines (62 loc) · 1.47 KB
/
err_details_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
package errors
import (
"database/sql"
"reflect"
"testing"
)
func TestErrorDetails(t *testing.T) {
cases := []struct {
name string
e *Error
want InternalDetails
}{
{name: "Empty", e: &Error{}, want: InternalDetails{Error: "no error"}},
{
name: "WithFields",
e: E(
WithOp("Get"),
WithUserMsg("irrelevant"),
WithText("beat dead horse: already dead"),
NotFound,
WithData(420),
WithErr(sql.ErrNoRows),
).(*Error),
want: InternalDetails{
Ops: []string{"Get"},
Kind: NotFound,
Error: "Get: not found: beat dead horse: already dead: sql: no rows in result set",
Data: 420,
},
},
{
name: "WithFieldsNested",
e: E(
WithOp("Get"),
WithUserMsg("irrelevant"),
WithText("beat dead horse: already dead"),
Internal,
WithData(420),
WithErr(E(
WithOp("Select"),
NotFound,
WithText("select data from table where column = ?"),
WithData("xyz"),
WithErr(sql.ErrNoRows),
)),
).(*Error),
want: InternalDetails{
Ops: []string{"Get", "Select"},
Kind: Internal,
Error: "Get: internal error: beat dead horse: already dead: Select: not found: select data from table where column = ?: sql: no rows in result set",
Data: []interface{}{420, "xyz"},
},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := tc.e.Details(); !reflect.DeepEqual(got, tc.want) {
t.Errorf("\nError.Details()=%#v; \nwant %#v", got, tc.want)
}
})
}
}