forked from mirror/logrus
Improve tests for logger.*Fn functions
This commit is contained in:
parent
d7edea4451
commit
ba4da53cff
|
@ -1,26 +1,31 @@
|
||||||
package logrus_test
|
package logrus_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLogger_LogFn(t *testing.T) {
|
func TestLogger_LogFn(t *testing.T) {
|
||||||
log.SetFormatter(&log.JSONFormatter{})
|
log.SetFormatter(&log.JSONFormatter{})
|
||||||
log.SetLevel(log.WarnLevel)
|
log.SetLevel(log.WarnLevel)
|
||||||
|
|
||||||
|
notCalled := 0
|
||||||
log.InfoFn(func() []interface{} {
|
log.InfoFn(func() []interface{} {
|
||||||
fmt.Println("This is never run")
|
notCalled++
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
"Hello",
|
"Hello",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
assert.Equal(t, 0, notCalled)
|
||||||
|
|
||||||
|
called := 0
|
||||||
log.ErrorFn(func() []interface{} {
|
log.ErrorFn(func() []interface{} {
|
||||||
fmt.Println("This runs")
|
called++
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
"Oopsi",
|
"Oopsi",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
assert.Equal(t, 1, called)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue