logrus/hooks/test/test_test.go

40 lines
907 B
Go
Raw Normal View History

2015-05-13 15:14:34 +03:00
package test
import (
"testing"
2017-05-19 15:00:16 +03:00
"github.com/sirupsen/logrus"
2015-05-13 15:14:34 +03:00
"github.com/stretchr/testify/assert"
)
func TestAllHooks(t *testing.T) {
assert := assert.New(t)
logger, hook := NewNullLogger()
2015-10-09 17:07:14 +03:00
assert.Nil(hook.LastEntry())
assert.Equal(0, len(hook.Entries))
2015-05-13 15:14:34 +03: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 17:07:14 +03:00
assert.Nil(hook.LastEntry())
2015-05-13 15:14:34 +03: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))
}