forked from mirror/logrus
Merge pull request #890 from sirupsen/hook_fire_order_test
Add a unit test to ensure hook are called in their registration order
This commit is contained in:
commit
659e47340e
24
hook_test.go
24
hook_test.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue