logrus/example_function_test.go

32 lines
500 B
Go
Raw Permalink Normal View History

package logrus_test
import (
"testing"
2020-05-19 18:02:33 +03:00
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestLogger_LogFn(t *testing.T) {
log.SetFormatter(&log.JSONFormatter{})
log.SetLevel(log.WarnLevel)
2020-05-19 18:02:33 +03:00
notCalled := 0
log.InfoFn(func() []interface{} {
2020-05-19 18:02:33 +03:00
notCalled++
return []interface{}{
"Hello",
}
})
2020-05-19 18:02:33 +03:00
assert.Equal(t, 0, notCalled)
2020-05-19 18:02:33 +03:00
called := 0
log.ErrorFn(func() []interface{} {
2020-05-19 18:02:33 +03:00
called++
return []interface{}{
"Oopsi",
}
})
2020-05-19 18:02:33 +03:00
assert.Equal(t, 1, called)
}