-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup_test.go
More file actions
67 lines (55 loc) · 1.25 KB
/
group_test.go
File metadata and controls
67 lines (55 loc) · 1.25 KB
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
package gexec
import (
"errors"
"testing"
"time"
)
func TestZero(t *testing.T) {
var g Group
res := make(chan error)
go func() { res <- g.Run() }()
select {
case err := <-res:
if err != nil {
t.Errorf("%v", err)
}
case <-time.After(100 * time.Millisecond):
t.Error("timeout")
}
}
func TestOne(t *testing.T) {
var (
g Group
myError = errors.New("foobar")
res = make(chan error)
)
g.Add(func() error { return myError }, func(error) {})
go func() { res <- g.Run() }()
select {
case err := <-res:
if expected, actual := myError, err; expected != actual {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
case <-time.After(100 * time.Millisecond):
t.Error("timeout")
}
}
func TestMany(t *testing.T) {
var (
g Group
interrupt = errors.New("interrupt")
cancel = make(chan struct{})
res = make(chan error)
)
g.Add(func() error { return interrupt }, func(error) {})
g.Add(func() error { <-cancel; return nil }, func(error) { close(cancel) })
go func() { res <- g.Run() }()
select {
case err := <-res:
if expected, actual := interrupt, err; expected != actual {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
case <-time.After(100 * time.Millisecond):
t.Error("timeout")
}
}