Skip to content

Commit

Permalink
Improve tests for logger.*Fn functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dgsb committed May 19, 2020
1 parent d7edea4 commit ba4da53
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions example_function_test.go
@@ -1,26 +1,31 @@
package logrus_test

import (
"fmt"
log "github.com/sirupsen/logrus"
"testing"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

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

notCalled := 0
log.InfoFn(func() []interface{} {
fmt.Println("This is never run")
return []interface{} {
notCalled++
return []interface{}{
"Hello",
}
})
assert.Equal(t, 0, notCalled)

called := 0
log.ErrorFn(func() []interface{} {
fmt.Println("This runs")
return []interface{} {
called++
return []interface{}{
"Oopsi",
}
})
assert.Equal(t, 1, called)
}

0 comments on commit ba4da53

Please sign in to comment.