Skip to content

Commit cad0908

Browse files
committed
test: modified unit test
1 parent 345fb79 commit cad0908

File tree

3 files changed

+72
-14
lines changed

3 files changed

+72
-14
lines changed

flow_test.go

+62-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11-
func TestExample(t *testing.T) {
11+
func Example() {
1212
f, counter := New(), 0
1313
showLevel := func() {
1414
counter++
@@ -40,11 +40,71 @@ func TestExample(t *testing.T) {
4040
f.Limit(10)
4141
// wait and add counter
4242
f.Run()
43+
// Unordered output:
44+
// 0
45+
// 1
46+
// 2
47+
// 3
48+
// 4
49+
// 5
50+
// 6
51+
// 7
52+
// 8
53+
// 9
54+
// 10
55+
// 11
56+
// 12
57+
// 13
58+
// 14
59+
// 15
60+
// 16
61+
// 17
62+
// 18
63+
// 19
64+
// 0
65+
// 1
66+
// 2
67+
// 3
68+
// 4
69+
// 5
70+
// 6
71+
// 7
72+
// 8
73+
// 9
74+
// 10
75+
// 11
76+
// 12
77+
// 13
78+
// 14
79+
// 15
80+
// 16
81+
// 17
82+
// 18
83+
// 19
84+
// level 1
85+
// level 2
4386
}
4487

45-
func TestNilFunc(t *testing.T) {
88+
func Example_NilFunc() {
4689
reset()
4790
New().With(nil).Next(nil).Run()
91+
// Output:
92+
// flow error: nil job
93+
// flow error: nil job
94+
}
95+
96+
func Example_SilentMode() {
97+
reset()
98+
New().With(func() {
99+
panic("u can see me")
100+
}).Run()
101+
102+
SilentMode = true
103+
New().With(func() {
104+
panic("u can not see me")
105+
}).Run()
106+
// Output:
107+
// flow panic: u can see me
48108
}
49109

50110
func TestConcurrent(t *testing.T) {
@@ -147,18 +207,6 @@ func TestLimit(t *testing.T) {
147207
f.Run()
148208
}
149209

150-
func TestSilentMode(t *testing.T) {
151-
reset()
152-
New().With(func() {
153-
panic("u can see me")
154-
}).Run()
155-
156-
SilentMode = true
157-
New().With(func() {
158-
panic("u can not see me")
159-
}).Run()
160-
}
161-
162210
func TestGlobalLimit(t *testing.T) {
163211
reset()
164212
Limit(4)

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/BouncyElf/flow
2+
3+
require github.com/stretchr/testify v1.3.0

go.sum

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
7+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

0 commit comments

Comments
 (0)