package logger_test import ( "bytes" "strings" "testing" "github.com/go-flucky/flucky/pkg/logger" "github.com/stretchr/testify/require" ) func TestLogger(t *testing.T) { require := require.New(t) stdoutBuffer := new(bytes.Buffer) stderrBuffer := new(bytes.Buffer) // LogLevelDebug l := logger.NewCustomLogger(logger.LogLevelDebug, stdoutBuffer, stderrBuffer) l.Debug("DEBUG") require.NotEmpty(stdoutBuffer.Bytes()) require.Empty(stderrBuffer.Bytes()) stdoutBuffer.Reset() stderrBuffer.Reset() // LogLevelInfo l = logger.NewCustomLogger(logger.LogLevelInfo, stdoutBuffer, stderrBuffer) l.Debug("DEBUG") require.Empty(stdoutBuffer.Bytes()) require.Empty(stderrBuffer.Bytes()) stdoutBuffer.Reset() stderrBuffer.Reset() l.Info("INFO") require.NotEmpty(stdoutBuffer.Bytes()) require.Empty(stderrBuffer.Bytes()) stringArray := strings.Split(stdoutBuffer.String(), ": ") require.Equal(2, len(stringArray)) require.Equal("INFO\n", stringArray[1]) stdoutBuffer.Reset() stderrBuffer.Reset() // LogLevelWarn l = logger.NewCustomLogger(logger.LogLevelWarn, stdoutBuffer, stderrBuffer) l.Warn("WARN") require.NotEmpty(stdoutBuffer.Bytes()) require.Empty(stderrBuffer.Bytes()) stringArray = strings.Split(stdoutBuffer.String(), ": ") require.Equal(2, len(stringArray)) require.Equal("WARN\n", stringArray[1]) stdoutBuffer.Reset() stderrBuffer.Reset() // LogLevelError l = logger.NewCustomLogger(logger.LogLevelError, stdoutBuffer, stderrBuffer) l.Error("ERROR") require.Empty(stdoutBuffer.Bytes()) require.NotEmpty(stderrBuffer.Bytes()) stringArray = strings.Split(stderrBuffer.String(), ": ") require.Equal(2, len(stringArray)) require.Equal("ERROR\n", stringArray[1]) }