-
Notifications
You must be signed in to change notification settings - Fork 28
/
reconfigurable_sink_test.go
65 lines (51 loc) · 1.53 KB
/
reconfigurable_sink_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 lager_test
import (
"code.cloudfoundry.org/lager/v3"
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("ReconfigurableSink", func() {
var (
testSink *lagertest.TestSink
sink *lager.ReconfigurableSink
)
BeforeEach(func() {
testSink = lagertest.NewTestSink()
sink = lager.NewReconfigurableSink(testSink, lager.INFO)
})
It("returns the current level", func() {
Expect(sink.GetMinLevel()).To(Equal(lager.INFO))
})
Context("when logging above the minimum log level", func() {
var log lager.LogFormat
BeforeEach(func() {
log = lager.LogFormat{LogLevel: lager.INFO, Message: "hello world"}
sink.Log(log)
})
It("writes to the given sink", func() {
Expect(testSink.Buffer().Contents()).To(MatchJSON(log.ToJSON()))
})
})
Context("when logging below the minimum log level", func() {
BeforeEach(func() {
sink.Log(lager.LogFormat{LogLevel: lager.DEBUG, Message: "hello world"})
})
It("does not write to the given writer", func() {
Expect(testSink.Buffer().Contents()).To(BeEmpty())
})
})
Context("when reconfigured to a new log level", func() {
BeforeEach(func() {
sink.SetMinLevel(lager.DEBUG)
})
It("writes logs above the new log level", func() {
log := lager.LogFormat{LogLevel: lager.DEBUG, Message: "hello world"}
sink.Log(log)
Expect(testSink.Buffer().Contents()).To(MatchJSON(log.ToJSON()))
})
It("returns the newly updated level", func() {
Expect(sink.GetMinLevel()).To(Equal(lager.DEBUG))
})
})
})