-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_test.go
71 lines (64 loc) · 1.42 KB
/
format_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
package main
import (
"bytes"
"testing"
)
func TestTime(t *testing.T) {
testCases := []struct {
name string
time string
want string
}{
{
name: "int",
time: "1673349503212",
want: "13:18:23",
},
{
name: "iso",
time: "2024-10-25T10:38:43.047213+03:00",
want: "10:38:43",
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
got := ts(tt.time)
if tt.want != got {
t.Errorf("error parsing timestamp: ts: %q want %q got %q", tt.time, tt.want, got)
}
})
}
}
func TestFormat(t *testing.T) {
testCases := []struct {
name string
line string
want string
}{
{
name: "with time",
line: "{\"time\":\"2024-10-25T10:38:42.796872+03:00\",\"level\":\"INFO\",\"msg\":\"Shut down HTTP\"}",
want: "[ INFO] 10:38:42 msg=Shut down HTTP \n",
},
{
name: "with timestamp",
line: "{\"timestamp\":\"2024-10-25T10:38:42.796872+03:00\",\"level\":\"INFO\",\"msg\":\"Shut down HTTP\"}",
want: "[ INFO] 10:38:42 msg=Shut down HTTP \n",
},
{
name: "with int",
line: "{\"timestamp\":\"1673349503212\",\"level\":\"INFO\",\"msg\":\"Shut down HTTP\"}",
want: "[ INFO] 13:18:23 msg=Shut down HTTP \n",
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
b := bytes.Buffer{}
format(tt.line, &b)
got := b.String()
if tt.want != got {
t.Errorf("error formating: line: %q want %q got %q", tt.line, tt.want, got)
}
})
}
}