-
Notifications
You must be signed in to change notification settings - Fork 5
Testing
Michael Kenney edited this page Aug 13, 2018
·
1 revision
bdlm/log has a built in facility for asserting the presence of log messages. This is implemented through the test hook and provides:
- decorators for existing logger (
test.NewLocalandtest.NewGlobal) which basically just add thetesthook - a test logger (
test.NewNullLogger) that just records log messages (and does not output any):
import(
"github.com/bdlm/log"
"github.com/bdlm/log/hooks/test"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSomething(t*testing.T){
logger, hook := test.NewNullLogger()
logger.Error("Helloerror")
assert.Equal(t, 1, len(hook.Entries))
assert.Equal(t, log.ErrorLevel, hook.LastEntry().Level)
assert.Equal(t, "Helloerror", hook.LastEntry().Message)
hook.Reset()
assert.Nil(t, hook.LastEntry())
}Which one will reach the other side of the river: The one who dreams of a raft, or the one that hitchhikes to the next bridge?