-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathlogger_test.go
158 lines (138 loc) · 4.28 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package scribe_test
import (
"bytes"
"testing"
"github.com/paketo-buildpacks/packit/v2/scribe"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/packit/v2/matchers"
)
func testLogger(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
buffer *bytes.Buffer
logger scribe.Logger
)
it.Before(func() {
buffer = bytes.NewBuffer(nil)
logger = scribe.NewLogger(buffer)
})
context("Title", func() {
it("prints the output with no indentation", func() {
logger.Title("some-%s", "title")
Expect(buffer.String()).To(Equal("some-title\n"))
})
})
context("Process", func() {
it("prints the output with one level of indentation", func() {
logger.Process("some-%s", "process")
Expect(buffer.String()).To(Equal(" some-process\n"))
})
})
context("Subprocess", func() {
it("prints the output with two levels of indentation", func() {
logger.Subprocess("some-%s", "subprocess")
Expect(buffer.String()).To(Equal(" some-subprocess\n"))
})
})
context("Action", func() {
it("prints the output with three levels of indentation", func() {
logger.Action("some-%s", "action")
Expect(buffer.String()).To(Equal(" some-action\n"))
})
})
context("Detail", func() {
it("prints the output with four levels of indentation", func() {
logger.Detail("some-%s", "detail")
Expect(buffer.String()).To(Equal(" some-detail\n"))
})
})
context("Subdetail", func() {
it("prints the output with five levels of indentation", func() {
logger.Subdetail("some-%s", "subdetail")
Expect(buffer.String()).To(Equal(" some-subdetail\n"))
})
})
context("Break", func() {
it("prints an empty line", func() {
logger.Break()
Expect(buffer.String()).To(Equal("\n"))
})
})
context("Debug", func() {
context("when Log Level is not set to DEBUG", func() {
it("does not print info", func() {
logger.Title("some-%s", "title")
logger.Process("some-%s", "process")
logger.Subprocess("some-%s", "subprocess")
logger.Action("some-%s", "action")
logger.Detail("some-%s", "detail")
logger.Subdetail("some-%s", "subdetail")
logger.Break()
logger.Debug.Title("some-debug-%s", "title")
logger.Debug.Process("some-debug-%s", "process")
logger.Debug.Subprocess("some-debug-%s", "subprocess")
logger.Debug.Action("some-debug-%s", "action")
logger.Debug.Detail("some-debug-%s", "detail")
logger.Debug.Subdetail("some-debug-%s", "subdetail")
logger.Debug.Break()
Expect(buffer.String()).To(ContainLines(
"some-title",
" some-process",
" some-subprocess",
" some-action",
" some-detail",
" some-subdetail",
"",
))
Expect(buffer.String()).NotTo(ContainLines(
"some-debug-title",
" some-debug-process",
" some-debug-subprocess",
" some-debug-action",
" some-debug-detail",
" some-debug-subdetail",
"",
))
})
})
context("when log level set to DEBUG", func() {
var debugLogger scribe.Logger
it.Before(func() {
debugLogger = scribe.NewLogger(buffer).WithLevel("DEBUG")
})
it("does print info", func() {
debugLogger.Title("some-%s", "title")
debugLogger.Process("some-%s", "process")
debugLogger.Subprocess("some-%s", "subprocess")
debugLogger.Action("some-%s", "action")
debugLogger.Detail("some-%s", "detail")
debugLogger.Subdetail("some-%s", "subdetail")
debugLogger.Break()
debugLogger.Debug.Title("some-debug-%s", "title")
debugLogger.Debug.Process("some-debug-%s", "process")
debugLogger.Debug.Subprocess("some-debug-%s", "subprocess")
debugLogger.Debug.Action("some-debug-%s", "action")
debugLogger.Debug.Detail("some-debug-%s", "detail")
debugLogger.Debug.Subdetail("some-debug-%s", "subdetail")
debugLogger.Debug.Break()
Expect(buffer.String()).To(ContainLines(
"some-title",
" some-process",
" some-subprocess",
" some-action",
" some-detail",
" some-subdetail",
"",
"some-debug-title",
" some-debug-process",
" some-debug-subprocess",
" some-debug-action",
" some-debug-detail",
" some-debug-subdetail",
"",
))
})
}, spec.Sequential())
})
}