Skip to content

Commit ba4da53

Browse files
committed
Improve tests for logger.*Fn functions
1 parent d7edea4 commit ba4da53

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

example_function_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
package logrus_test
22

33
import (
4-
"fmt"
5-
log "github.com/sirupsen/logrus"
64
"testing"
5+
6+
log "github.com/sirupsen/logrus"
7+
"github.com/stretchr/testify/assert"
78
)
89

910
func TestLogger_LogFn(t *testing.T) {
1011
log.SetFormatter(&log.JSONFormatter{})
1112
log.SetLevel(log.WarnLevel)
1213

14+
notCalled := 0
1315
log.InfoFn(func() []interface{} {
14-
fmt.Println("This is never run")
15-
return []interface{} {
16+
notCalled++
17+
return []interface{}{
1618
"Hello",
1719
}
1820
})
21+
assert.Equal(t, 0, notCalled)
1922

23+
called := 0
2024
log.ErrorFn(func() []interface{} {
21-
fmt.Println("This runs")
22-
return []interface{} {
25+
called++
26+
return []interface{}{
2327
"Oopsi",
2428
}
2529
})
30+
assert.Equal(t, 1, called)
2631
}

0 commit comments

Comments
 (0)