-
Notifications
You must be signed in to change notification settings - Fork 2
/
waterfall_test.go
71 lines (62 loc) · 1.78 KB
/
waterfall_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
package async_test
import (
"fmt"
"github.com/Southern/async"
"testing"
"time"
)
func TestWaterfall(t *testing.T) {
Status("Calling Waterfall")
async.Waterfall([]async.Routine{
func(done async.Done, args ...interface{}) {
Status("First waterfall function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(nil, "arg1", "arg2", "arg3")
},
func(done async.Done, args ...interface{}) {
Status("Second waterfall function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(nil, "arg4", "arg5", "arg6")
},
func(done async.Done, args ...interface{}) {
Status("Third waterfall function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(nil, "arg7", "arg8", "arg9")
},
}, func(err error, results ...interface{}) {
if err != nil {
t.Errorf("Waterfall threw an unexpected error: %+v", err)
return
}
Status("Waterfall completed with results: %+v", results)
})
}
func TestWaterfallError(t *testing.T) {
Status("Calling Waterfall")
async.Waterfall([]async.Routine{
func(done async.Done, args ...interface{}) {
Status("First waterfall function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(nil, "arg1", "arg2", "arg3")
},
func(done async.Done, args ...interface{}) {
Status("Second waterfall function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(fmt.Errorf("Test error"))
},
func(done async.Done, args ...interface{}) {
t.Errorf("The second waterfall function did not stop when it errored.")
},
}, func(err error, results ...interface{}) {
if err != nil {
Status("Waterfall exited with error: %+v", err)
return
}
t.Errorf("Waterfall did not throw an error as expected")
})
}