-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformatter_with_response_body_test.go
72 lines (62 loc) · 1.53 KB
/
formatter_with_response_body_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
package httplog
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestResponseBodyLogFormatterEmpty(t *testing.T) {
bodyParams := LogFormatterParams{
RouterName: "TEST",
StatusCode: 200,
ClientIP: "20.20.20.20",
Method: "GET",
Body: []byte(""),
Path: "/",
}
assert.Equal(t,
"===\n EMPTY BODY \n===\n",
ResponseBodyLogFormatter(bodyParams),
)
}
func TestResponseBodyLogFormatterText(t *testing.T) {
bodyParams := LogFormatterParams{
RouterName: "TEST",
StatusCode: 200,
ClientIP: "20.20.20.20",
Method: "GET",
Body: []byte("I am text body!"),
Path: "/",
}
assert.Equal(t,
"===\n TEXT BODY:\nI am text body!\n===\n",
ResponseBodyLogFormatter(bodyParams),
)
}
func TestResponseBodyLogFormatterTextColor(t *testing.T) {
bodyParams := LogFormatterParams{
RouterName: "TEST",
StatusCode: 200,
ClientIP: "20.20.20.20",
Method: "GET",
Body: []byte("I am text body!"),
Path: "/",
isTerm: true,
}
assert.Equal(t,
"===\n\x1b[97;44m TEXT BODY:\x1b[0m\nI am text body!\n===\n",
ResponseBodyLogFormatter(bodyParams),
)
}
func TestResponseBodyLogFormatterJSON(t *testing.T) {
bodyParams := LogFormatterParams{
RouterName: "TEST",
StatusCode: 200,
ClientIP: "20.20.20.20",
Method: "GET",
Body: []byte(`{"name":"John", "age":30, "car":null}`),
Path: "/",
}
assert.Equal(t,
"===\n JSON BODY:\n{\n \"age\": 30,\n \"car\": null,\n \"name\": \"John\"\n}\n===\n",
ResponseBodyLogFormatter(bodyParams),
)
}