forked from rocksolidlabs/gin-logrus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathginlogrus_test.go
65 lines (56 loc) · 1.64 KB
/
ginlogrus_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
package ginlogrus
import (
"os"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
const checkMark = "\u2713"
const ballotX = "\u2717"
func Test_ErrorLogger(t *testing.T) {
middleware := ErrorLogger()
assert.NotNil(t, middleware, "Can't get ErrorLogger middleware")
}
func Test_Logger(t *testing.T) {
log := logrus.New()
middleware := Logger(log, "TEST", false, true, os.Stdout, logrus.WarnLevel)
assert.NotNil(t, middleware, "Can't get Logger middleware")
}
func Test_colorForMethod(t *testing.T) {
colors := map[string]string{
"GET": blue,
"POST": cyan,
"PUT": yellow,
"HEAD": magenta,
"OPTIONS": white,
"UNKNOWN": reset}
for method, color := range colors {
expect := colorForMethod(method)
assert.NotNil(t, expect, "Can't get color from method %s %s",
method, ballotX)
t.Logf("Check if color %s%s%s is the right one for this method",
string(expect), method, reset)
if assert.Equal(t, expect, color, "Method %s has NOT the right color %s",
method, ballotX) {
t.Logf("Method %s has the right color %s", method, checkMark)
}
}
}
func Test_colorForStatus(t *testing.T) {
colors := map[int]string{
200: green,
301: white,
404: yellow,
500: red}
for status, color := range colors {
expect := colorForStatus(status)
assert.NotNil(t, expect, "Can't get color from status %d %s",
status, ballotX)
t.Logf("Check if color %s%d%s is the right one for this status",
string(expect), status, reset)
if assert.Equal(t, expect, color, "Status %d has NOT the right color %s",
status, ballotX) {
t.Logf("Status %d has the right color %s", status, checkMark)
}
}
}