From ba4da53cffb0ed6b42e5cfa334a011e55448f7db Mon Sep 17 00:00:00 2001 From: David Bariod Date: Tue, 19 May 2020 17:02:33 +0200 Subject: [PATCH] Improve tests for logger.*Fn functions --- example_function_test.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/example_function_test.go b/example_function_test.go index f61460e..dda890d 100644 --- a/example_function_test.go +++ b/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) }