mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-26 13:49:21 +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) {
|
||||
|
||||
h := NewEventHook()
|
||||
i := 0
|
||||
x := 0
|
||||
|
||||
h.AddHook("sample", func() {
|
||||
i++
|
||||
})
|
||||
for i := 0; i < 100; i ++ {
|
||||
h.AddHook("sample", func() {
|
||||
x++
|
||||
})
|
||||
}
|
||||
|
||||
h.AddHook("sample", func() {
|
||||
i++
|
||||
h.AddHook("noop", func() {
|
||||
x++
|
||||
})
|
||||
|
||||
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")
|
||||
|
||||
assert.Equal(t, i, 0, "should not execute any hook")
|
||||
assert.Equal(t, x, 0, "should not execute any hook")
|
||||
|
||||
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