-
Notifications
You must be signed in to change notification settings - Fork 3
/
handler_test.go
47 lines (39 loc) · 1.17 KB
/
handler_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
package fire
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCombine(t *testing.T) {
withTester(t, func(t *testing.T, tester *Tester) {
assert.PanicsWithValue(t, "fire: callback does not support stage", func() {
Combine("foo", Validator, C("bar", Modifier, All(), func(ctx *Context) error {
return nil
}), C("baz", Validator, All(), func(ctx *Context) error {
return nil
}))
})
var ret []string
cb := Combine("foo", Modifier|Validator, C("bar", Modifier, All(), func(ctx *Context) error {
ret = append(ret, "bar")
return nil
}), C("baz", Validator, All(), func(ctx *Context) error {
ret = append(ret, "baz")
return nil
}))
err := tester.RunHandler(nil, cb.Handler)
assert.NoError(t, err)
assert.Empty(t, ret)
ret = nil
err = tester.RunHandler(&Context{Stage: Modifier}, cb.Handler)
assert.NoError(t, err)
assert.Equal(t, []string{"bar"}, ret)
ret = nil
err = tester.RunHandler(&Context{Stage: Validator}, cb.Handler)
assert.NoError(t, err)
assert.Equal(t, []string{"baz"}, ret)
ret = nil
err = tester.RunHandler(&Context{Stage: Decorator}, cb.Handler)
assert.NoError(t, err)
assert.Empty(t, ret)
})
}