-
Notifications
You must be signed in to change notification settings - Fork 12
/
runners_test.go
68 lines (65 loc) · 1.66 KB
/
runners_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
package gohalt
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRunners(t *testing.T) {
cctx, cancel := context.WithCancel(context.Background())
cancel()
testerr := errors.New("test")
table := map[string]struct {
r Runner
run Runnable
err error
}{
"Runner sync should return error on throttling": {
r: NewRunnerSync(context.Background(), tmock{aerr: testerr}),
run: nope,
err: testerr,
},
"Runner sync should return error on realising error": {
r: NewRunnerSync(context.Background(), tmock{rerr: testerr}),
run: nope,
err: testerr,
},
"Runner sync should return error on runnable error": {
r: NewRunnerSync(context.Background(), tmock{}),
run: use(testerr),
err: testerr,
},
"Runner sync should return error on canceled context": {
r: NewRunnerSync(cctx, tmock{}),
run: nope,
err: cctx.Err(),
},
"Runner async should return error on throttling": {
r: NewRunnerAsync(context.Background(), tmock{aerr: testerr}),
run: nope,
err: testerr,
},
"Runner async should return error on realising error": {
r: NewRunnerAsync(context.Background(), tmock{rerr: testerr}),
run: nope,
err: testerr,
},
"Runner async should return error on runnable error": {
r: NewRunnerAsync(context.Background(), tmock{}),
run: use(testerr),
err: testerr,
},
"Runner async should return error on canceled context": {
r: NewRunnerAsync(cctx, tmock{}),
run: nope,
err: cctx.Err(),
},
}
for tname, tcase := range table {
t.Run(tname, func(t *testing.T) {
tcase.r.Run(tcase.run)
err := tcase.r.Result()
assert.Equal(t, tcase.err, err)
})
}
}