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