logrus/hooks/test/test_test.go

40 lines
907 B
Go
Raw Normal View History

2015-05-13 12:14:34 +00:00
package test
import (
"testing"
2017-05-19 12:00:16 +00:00
"github.com/sirupsen/logrus"
2015-05-13 12:14:34 +00:00
"github.com/stretchr/testify/assert"
)
func TestAllHooks(t *testing.T) {
assert := assert.New(t)
logger, hook := NewNullLogger()
2015-10-09 14:07:14 +00:00
assert.Nil(hook.LastEntry())
assert.Equal(0, len(hook.Entries))
2015-05-13 12:14:34 +00:00
logger.Error("Hello error")
assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
assert.Equal("Hello error", hook.LastEntry().Message)
assert.Equal(1, len(hook.Entries))
logger.Warn("Hello warning")
assert.Equal(logrus.WarnLevel, hook.LastEntry().Level)
assert.Equal("Hello warning", hook.LastEntry().Message)
assert.Equal(2, len(hook.Entries))
hook.Reset()
2015-10-09 14:07:14 +00:00
assert.Nil(hook.LastEntry())
2015-05-13 12:14:34 +00:00
assert.Equal(0, len(hook.Entries))
hook = NewGlobal()
logrus.Error("Hello error")
assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level)
assert.Equal("Hello error", hook.LastEntry().Message)
assert.Equal(1, len(hook.Entries))
}