-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmask_test.go
116 lines (105 loc) · 2.41 KB
/
mask_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package tracer
import (
"errors"
"fmt"
"testing"
)
func Test_Tracer_Mask(t *testing.T) {
var (
testErrorOne = fmt.Errorf("testErrorOne")
testErrorTwo = &Error{Kind: "testErrorTwo"}
)
testCases := []struct {
errFunc func() error
cause error
}{
// Case 000 ensures that without error there is no cause.
{
errFunc: func() error {
return nil
},
cause: nil,
},
// Case 001 does not use error wrapping. The error is simply made up by
// fmt.Errorf.
{
errFunc: func() error {
return testErrorOne
},
cause: testErrorOne,
},
// Case 002 does not use error wrapping. The error is simply made up by
// using the tracer error type.
{
errFunc: func() error {
return testErrorTwo
},
cause: testErrorTwo,
},
// Case 003 does error wrapping one time. The error is simply made up by
// fmt.Errorf.
{
errFunc: func() error {
return Mask(testErrorOne)
},
cause: testErrorOne,
},
// Case 004 does error wrapping one time. The error is simply made up by
// using the tracer error type.
{
errFunc: func() error {
return Mask(testErrorTwo)
},
cause: testErrorTwo,
},
// Case 005 does error wrapping two times. The error is simply made up by
// fmt.Errorf.
{
errFunc: func() error {
var err error
err = Mask(testErrorOne)
err = Mask(err)
return err
},
cause: testErrorOne,
},
// Case 006 does error wrapping two times. The error is simply made up by
// using the tracer error type.
{
errFunc: func() error {
var err error
err = Mask(testErrorTwo)
err = Mask(err)
return err
},
cause: testErrorTwo,
},
// Case 007 does error wrapping one time, while the first wrapping is
// annotated. The error is simply made up by using the tracer error type.
{
errFunc: func() error {
return Maskf(testErrorTwo, "annotation")
},
cause: testErrorTwo,
},
// Case 008 does error wrapping two times, while the first wrapping is
// annotated. The error is simply made up by using the tracer error type.
{
errFunc: func() error {
var err error
err = Maskf(testErrorTwo, "annotation")
err = Mask(err)
return err
},
cause: testErrorTwo,
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("%03d", i), func(t *testing.T) {
cause := tc.errFunc()
if !errors.Is(cause, tc.cause) {
t.Fatalf("expected %#v got %#v", tc.cause, cause)
}
})
}
}