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