From 9d41e80edcd38e435d55d37313dbaa208dcd57a1 Mon Sep 17 00:00:00 2001 From: raziman Date: Fri, 19 Feb 2021 22:22:36 +0800 Subject: [PATCH] add hook test --- hook/hook_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/hook/hook_test.go b/hook/hook_test.go index e64c3d1..87dc63a 100644 --- a/hook/hook_test.go +++ b/hook/hook_test.go @@ -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'") }