-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathlogger_test.go
64 lines (52 loc) · 1.14 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
package libbuildpack_test
import (
"bytes"
"os"
"github.com/cloudfoundry/libbuildpack"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Logger", func() {
var (
err error
logger *libbuildpack.Logger
buffer *bytes.Buffer
)
BeforeEach(func() {
buffer = new(bytes.Buffer)
logger = libbuildpack.NewLogger(buffer)
})
Describe("Debug", func() {
var (
bpDebug string
oldBpDebug string
)
JustBeforeEach(func() {
oldBpDebug = os.Getenv("BP_DEBUG")
err = os.Setenv("BP_DEBUG", bpDebug)
Expect(err).To(BeNil())
})
AfterEach(func() {
err = os.Setenv("BP_DEBUG", oldBpDebug)
Expect(err).To(BeNil())
})
Context("BP_DEBUG is set", func() {
BeforeEach(func() {
bpDebug = "true"
})
It("Logs the message", func() {
logger.Debug("detailed info")
Expect(buffer.String()).To(ContainSubstring("\033[34;1mDEBUG:\033[0m detailed info"))
})
})
Context("BP_DEBUG is not set", func() {
BeforeEach(func() {
bpDebug = ""
})
It("Does not log the message", func() {
logger.Debug("detailed info")
Expect(buffer.String()).To(Equal(""))
})
})
})
})