mirror of https://github.com/sirupsen/logrus.git
Add a unit test to ensure hook are called in their registration order
This commit is contained in:
parent
11dad09cee
commit
0f544bf278
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