github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/log/logger_test.go (about)

     1  package log
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/jonboulle/clockwork"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestColoring(t *testing.T) {
    12  	zeroClock := clockwork.NewFakeClock()
    13  	fullDuration := zeroClock.Now().Sub(time.Date(1984, 4, 4, 0, 0, 0, 0, time.UTC))
    14  	zeroClock.Advance(-fullDuration) // set zero time
    15  	for _, tt := range []struct {
    16  		l   *defaultLogger
    17  		msg string
    18  		exp string
    19  	}{
    20  		{
    21  			l: &defaultLogger{
    22  				coloring: true,
    23  				clock:    zeroClock,
    24  			},
    25  			msg: "test",
    26  			exp: "\u001B[31m1984-04-04 00:00:00.000 \u001B[0m\u001B[101mERROR\u001B[0m\u001B[31m 'test.scope' => message\u001B[0m", //nolint:lll
    27  		},
    28  		{
    29  			l: &defaultLogger{
    30  				coloring: false,
    31  				clock:    zeroClock,
    32  			},
    33  			msg: "test",
    34  			exp: "1984-04-04 00:00:00.000 ERROR 'test.scope' => message",
    35  		},
    36  	} {
    37  		t.Run("", func(t *testing.T) {
    38  			act := tt.l.format([]string{"test", "scope"}, "message", ERROR)
    39  			require.Equal(t, tt.exp, act)
    40  		})
    41  	}
    42  }