mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-28 13:48:53 +08:00
add hook test
This commit is contained in:
parent
af336e1a60
commit
9d41e80edc
@ -29,27 +29,29 @@ func TestAddHook(t *testing.T) {
|
|||||||
func TestRunHooks(t *testing.T) {
|
func TestRunHooks(t *testing.T) {
|
||||||
|
|
||||||
h := NewEventHook()
|
h := NewEventHook()
|
||||||
i := 0
|
x := 0
|
||||||
|
|
||||||
|
for i := 0; i < 100; i ++ {
|
||||||
h.AddHook("sample", func() {
|
h.AddHook("sample", func() {
|
||||||
i++
|
x++
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
h.AddHook("sample", func() {
|
h.AddHook("noop", func() {
|
||||||
i++
|
x++
|
||||||
})
|
})
|
||||||
|
|
||||||
h.AddHook("noop", func() {
|
h.AddHook("noop", func() {
|
||||||
i++
|
x++
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.Equal(t, i, 0, "should not execute any hook")
|
assert.Equal(t, x, 0, "should not execute any hook")
|
||||||
|
|
||||||
h.RunHooks("x")
|
h.RunHooks("x")
|
||||||
|
|
||||||
assert.Equal(t, i, 0, "should not execute any hook")
|
assert.Equal(t, x, 0, "should not execute any hook")
|
||||||
|
|
||||||
h.RunHooks("sample")
|
h.RunHooks("sample")
|
||||||
|
|
||||||
assert.Equal(t, i, 2, "should only execute event 'sample'")
|
assert.Equal(t, x, 100, "should only execute event 'sample'")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user