-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
100 lines (85 loc) · 1.59 KB
/
logger_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package cogol
import (
"fmt"
"github.com/fatih/color"
"testing"
)
func TestDefaultLogger(t *testing.T) {
cgl := Init(t)
g := cgl.Group("Logger")
{
g.BeforeEach(func(c *Context) {
c.Expect(c.Log()).ToBeNotNil()
})
g.T("Info", func(c *Context) {
c.Log().Info("hello world")
c.Expect(c.test.logs).ToBe(
[]string{
fmt.Sprintf(
"%v %v",
color.HiBlueString("\t\tINFO"),
"hello world\n\n",
),
},
)
})
g.T("Infof", func(c *Context) {
c.Log().Infof("%v world", "hello")
c.Expect(c.test.logs).ToBe(
[]string{
fmt.Sprintf(
"%v %v",
color.HiBlueString("\t\tINFO"),
"hello world\n\n",
),
},
)
})
g.T("Error", func(c *Context) {
c.Log().Error("hello world")
c.Expect(c.test.logs).ToBe(
[]string{
fmt.Sprintf(
"%v %v",
color.HiRedString("\t\tERROR"),
"hello world\n\n",
),
},
)
})
g.T("Errorf", func(c *Context) {
c.Log().Errorf("%v world", "hello")
c.Expect(c.test.logs).ToBe(
[]string{
fmt.Sprintf(
"%v %v",
color.HiRedString("\t\tERROR"),
"hello world\n\n",
),
},
)
})
g.T("Multiple logger statements", func(c *Context) {
c.Log().Info("Hello")
c.Log().Error("Cogol")
c.Expect(c.test.logs).ToBe(
[]string{
fmt.Sprintf(
"%v %v",
color.HiBlueString("\t\tINFO"),
"Hello\n\n",
),
fmt.Sprintf(
"%v %v",
color.HiRedString("\t\tERROR"),
"Cogol\n\n",
),
},
)
})
g.AfterEach(func(c *Context) {
c.test.logs = []string{}
})
}
cgl.Process()
}