-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformatter_test.go
61 lines (53 loc) · 1.78 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
package httplog
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDefaultLogFormatter(t *testing.T) {
timeStamp := time.Unix(1544173902, 0).UTC()
termFalseParam := LogFormatterParams{
RouterName: "TEST",
TimeStamp: timeStamp,
StatusCode: 200,
Latency: time.Second * 5,
ClientIP: "20.20.20.20",
Method: "GET",
Path: "/",
isTerm: false,
}
termTrueParam := LogFormatterParams{
RouterName: "TEST",
TimeStamp: timeStamp,
StatusCode: 200,
Latency: time.Second * 5,
ClientIP: "20.20.20.20",
Method: "GET",
Path: "/",
isTerm: true,
}
termTrueLongDurationParam := LogFormatterParams{
RouterName: "TEST",
TimeStamp: timeStamp,
StatusCode: 200,
Latency: time.Millisecond * 9876543210,
ClientIP: "20.20.20.20",
Method: "GET",
Path: "/",
isTerm: true,
}
termFalseLongDurationParam := LogFormatterParams{
RouterName: "TEST",
TimeStamp: timeStamp,
StatusCode: 200,
Latency: time.Millisecond * 9876543210,
ClientIP: "20.20.20.20",
Method: "GET",
Path: "/",
isTerm: false,
}
assert.Equal(t, "[TEST] 2018/12/07 - 09:11:42 | 200 | 5s | 20.20.20.20 | GET \"/\"\n", DefaultLogFormatter(termFalseParam))
assert.Equal(t, "[TEST] 2018/12/07 - 09:11:42 | 200 | 2743h29m3s | 20.20.20.20 | GET \"/\"\n", DefaultLogFormatter(termFalseLongDurationParam))
assert.Equal(t, "[TEST] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m \"/\"\n", DefaultLogFormatter(termTrueParam))
assert.Equal(t, "[TEST] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 2743h29m3s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m \"/\"\n", DefaultLogFormatter(termTrueLongDurationParam))
}