github.com/drycc/workflow-cli@v1.5.3-0.20240322092846-d4ee25983af9/pkg/logging/log_unix_test.go (about)

     1  //go:build linux || darwin
     2  // +build linux darwin
     3  
     4  package logging
     5  
     6  import (
     7  	"bytes"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  type colorsTestCase struct {
    14  	Input    string
    15  	Expected string
    16  }
    17  
    18  func TestChooseColor(t *testing.T) {
    19  	t.Parallel()
    20  
    21  	colors := []colorsTestCase{
    22  		{"INFO", "\033[35m"},
    23  		{"a", "\033[32m"},
    24  		{"b", "\033[33m"},
    25  		{"c", "\033[34m"},
    26  		{"d", "\033[39m"},
    27  		{"e", "\033[36m"},
    28  		{"f", "\033[31m"},
    29  	}
    30  	for _, color := range colors {
    31  		assert.Equal(t, chooseColor(color.Input), color.Expected, "color")
    32  	}
    33  }
    34  
    35  func TestPrintLogs(t *testing.T) {
    36  	var b bytes.Buffer
    37  	PrintLog(&b, "INFO [test]: testing")
    38  	assert.Equal(t, b.String(), "\033[35mINFO [test]: testing\033[0m\n", "log line")
    39  	b.Reset()
    40  	// Regression test for https://github.com/drycc/drycc/issues/4420
    41  	PrintLog(&b, "\nDone preparing production files\n\n\u001b[4mRunning \"concat:plugins\" (concat) task\u001b[24m\n")
    42  	assert.Equal(t, b.String(),
    43  		"\033[31m\nDone preparing production files\n\n\u001b[4mRunning \"concat:plugins\" (concat) task\u001b[24m\n\033[0m\n", "log line")
    44  }