-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathret1_test.go
117 lines (100 loc) · 2.13 KB
/
ret1_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
117
package testing_test
import (
"errors"
"testing"
. "github.com/rocketlaunchr/testing-go"
)
func ret1Val(Panic bool) string {
if Panic {
panic("panic")
}
return "abc"
}
func TestRet1(t *testing.T) {
testCases := []struct {
in bool
ExpOut interface{}
}{
{true, PanicExpected},
{false, Not{PanicExpected}},
{false, "abc"},
{false, Not{"abcd"}},
}
tcfg := NewTestConfig(t)
for idx, tc := range testCases {
tcfg.Run1(Sprintf("[%d]: %v", idx, tc.in), tc, func(t *testing.T) interface{} {
return ret1Val(tc.in)
})
}
}
var (
errSample1 = errors.New("sample error 1")
errSample2 = errors.New("sample error 2")
)
func retErr(Panic bool) error {
if Panic {
panic("panic")
}
return errSample1
}
func TestRetErr(t *testing.T) {
testCases := []struct {
in bool
ExpErr error
}{
{true, PanicExpected},
{false, Not{PanicExpected}},
{false, errSample1},
{false, ErrAny},
{false, Not{errSample2}},
{false, ErrContains{"1"}},
{false, Not{ErrContains{"2"}}},
{false, Not{nil}},
{true, Is{PanicExpected}},
{false, Is{Not{PanicExpected}}},
{false, Is{errSample1}},
{false, Is{ErrAny}},
{false, Is{Not{errSample2}}},
{false, Is{ErrContains{"1"}}},
{false, Is{Not{ErrContains{"2"}}}},
{false, Is{Not{nil}}},
}
tcfg := NewTestConfig(t)
for idx, tc := range testCases {
tcfg.RunErr(Sprintf("[%d]: %v", idx, tc.in), tc, func(t *testing.T) error {
return retErr(tc.in)
})
}
}
func retErrNil(Panic bool) error {
if Panic {
panic("panic")
}
return nil
}
func TestRetErrNil(t *testing.T) {
testCases := []struct {
in bool
ExpErr error
}{
{true, PanicExpected},
{false, nil},
{false, Not{Not{nil}}},
{false, Not{PanicExpected}},
{false, Not{ErrAny}},
{false, Not{errSample1}},
{false, Not{ErrContains{"2"}}},
{true, Is{PanicExpected}},
{false, Is{nil}},
{false, Is{Not{PanicExpected}}},
{false, Is{Not{ErrAny}}},
{false, Is{Not{errSample1}}},
{false, Is{Not{ErrContains{"2"}}}},
}
tcfg := NewTestConfig(t)
for idx, tc := range testCases {
tcfg.RunErr(Sprintf("[%d]: %v", idx, tc.in), tc, func(t *testing.T) error {
return retErrNil(tc.in)
})
}
}