Skip to content

Commit

Permalink
Merge pull request sirupsen#890 from sirupsen/hook_fire_order_test
Browse files Browse the repository at this point in the history
Add a unit test to ensure hook are called in their registration order
  • Loading branch information
dgsb committed Jan 17, 2019
2 parents 87c44ef + 1beb6e8 commit 55d982c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions hook_test.go
Expand Up @@ -190,3 +190,27 @@ func TestAddHookRace(t *testing.T) {
// actually assert on the hook
})
}

type HookCallFunc struct {
F func()
}

func (h *HookCallFunc) Levels() []Level {
return AllLevels
}

func (h *HookCallFunc) Fire(e *Entry) error {
h.F()
return nil
}

func TestHookFireOrder(t *testing.T) {
checkers := []string{}
h := LevelHooks{}
h.Add(&HookCallFunc{F: func() { checkers = append(checkers, "first hook") }})
h.Add(&HookCallFunc{F: func() { checkers = append(checkers, "second hook") }})
h.Add(&HookCallFunc{F: func() { checkers = append(checkers, "third hook") }})

h.Fire(InfoLevel, &Entry{})
require.Equal(t, []string{"first hook", "second hook", "third hook"}, checkers)
}

0 comments on commit 55d982c

Please sign in to comment.