-
Notifications
You must be signed in to change notification settings - Fork 14
/
formatter_test.go
84 lines (63 loc) · 4.05 KB
/
formatter_test.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package logging
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestFormatFromString(t *testing.T) {
assert.Equal(t, FormatFromString("FuLl"), FULL, "formats are case insensitive")
assert.Equal(t, FormatFromString("SimplE"), SIMPLE, "formats are case insensitive")
assert.Equal(t, FormatFromString("MinimalTagged"), MINIMALTAGGED, "formats are case insensitive")
assert.Equal(t, FormatFromString("Minimal"), MINIMAL, "formats are case insensitive")
assert.Equal(t, FormatFromString("foo"), SIMPLE, "default is simple")
}
func TestFormatGetFormatter(t *testing.T) {
assert.Equal(t, GetFormatter(FULL), LogFormatter(fullFormat), "should be full")
assert.Equal(t, GetFormatter(SIMPLE), LogFormatter(simpleFormat), "should be simple")
assert.Equal(t, GetFormatter(MINIMALTAGGED), LogFormatter(minimalWithTagsFormat), "should be minimal tagged")
assert.Equal(t, GetFormatter(MINIMAL), LogFormatter(minimalFormat), "should be minimal")
assert.Equal(t, GetFormatter(LogFormat("foo")), LogFormatter(simpleFormat), "should be simple")
}
func TestFormatFull(t *testing.T) {
at := time.Unix(1000, 0)
original := at.AddDate(0, 0, 1)
expected := "[Dec 31 16:16:40.000] [INFO] [one two] [replayed from Jan 1 16:16:40.000] hello"
assert.Equal(t, fullFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
expected = "[Dec 31 16:16:40.000] [INFO] [replayed from Jan 1 16:16:40.000] hello"
assert.Equal(t, fullFormat(INFO, nil, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
expected = "[Dec 31 16:16:40.000] [INFO] [one two] hello"
assert.Equal(t, fullFormat(INFO, []string{"one", "two"}, "hello", at, at), expected, fmt.Sprintf("should equal %s", expected))
expected = "[Dec 31 16:16:40.000] [INFO] [one two] [replayed from Jan 1 16:16:40.000] hello"
assert.Equal(t, fullFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
}
func TestFormatSimple(t *testing.T) {
at := time.Unix(1000, 0)
original := at.AddDate(0, 0, 1)
expected := "[Dec 31 16:16:40] [INFO] hello"
assert.Equal(t, simpleFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
assert.Equal(t, simpleFormat(INFO, nil, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
assert.Equal(t, simpleFormat(INFO, []string{"one", "two"}, "hello", at, at), expected, fmt.Sprintf("should equal %s", expected))
assert.Equal(t, simpleFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
}
func TestFormatMinimal(t *testing.T) {
at := time.Unix(1000, 0)
original := at.AddDate(0, 0, 1)
expected := "hello"
assert.Equal(t, minimalFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
assert.Equal(t, minimalFormat(INFO, nil, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
assert.Equal(t, minimalFormat(INFO, []string{"one", "two"}, "hello", at, at), expected, fmt.Sprintf("should equal %s", expected))
assert.Equal(t, minimalFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
}
func TestFormatMinimalWithTags(t *testing.T) {
at := time.Unix(1000, 0)
original := at.AddDate(0, 0, 1)
expected := "[INFO] [one two] hello"
assert.Equal(t, minimalWithTagsFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
expected = "[INFO] hello"
assert.Equal(t, minimalWithTagsFormat(INFO, nil, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
expected = "[INFO] [one two] hello"
assert.Equal(t, minimalWithTagsFormat(INFO, []string{"one", "two"}, "hello", at, at), expected, fmt.Sprintf("should equal %s", expected))
expected = "[INFO] [one two] hello"
assert.Equal(t, minimalWithTagsFormat(INFO, []string{"one", "two"}, "hello", at, original), expected, fmt.Sprintf("should equal %s", expected))
}