github.com/engineyard/workflow-cli@v2.21.6+incompatible/pkg/logging/log_unix_test.go (about)

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