-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombine_test.go
57 lines (50 loc) · 1.3 KB
/
combine_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
package errassert_test
import (
"errors"
"testing"
"github.com/zoido/errassert"
)
func TestWant(t *testing.T) {
type testCase struct {
assertions []errassert.ErrorAssertion
want error
}
run := func(t *testing.T, tc testCase) {
// When
got := errassert.Want(tc.assertions...)(nil)
// Then
if !errorEq(got, tc.want) {
t.Errorf("Want(%v) = %v; want %v", tc.assertions, got, tc.want)
}
}
testCases := map[string]testCase{
"single pass": {
assertions: []errassert.ErrorAssertion{passAssertion},
},
"single fail": {
assertions: []errassert.ErrorAssertion{failAssertion},
want: errors.New(failMsg),
},
"multiple pass": {
assertions: []errassert.ErrorAssertion{passAssertion, passAssertion},
},
"first fail": {
assertions: []errassert.ErrorAssertion{failAssertion, passAssertion},
want: errors.New(failMsg),
},
"second fail": {
assertions: []errassert.ErrorAssertion{passAssertion, failAssertion},
want: errors.New(failMsg),
},
"both fail": {
assertions: []errassert.ErrorAssertion{
func(err error) error { return errors.New("first") },
func(err error) error { return errors.New("second") },
},
want: errors.New("first"),
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) { run(t, tc) })
}
}