-
Notifications
You must be signed in to change notification settings - Fork 28
/
truncating_sink_test.go
55 lines (49 loc) · 1.54 KB
/
truncating_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
package lager_test
import (
"code.cloudfoundry.org/lager/v3"
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
const longString = "aaaaaaaaaaaaaaaaaaaaaaaaa"
var _ = Describe("TruncatingSink", func() {
var (
sink lager.Sink
testSink *lagertest.TestSink
)
type dummyStruct struct {
A string
}
BeforeEach(func() {
testSink = lagertest.NewTestSink()
sink = lager.NewTruncatingSink(testSink, 20)
})
Context("when given data that has only short strings", func() {
BeforeEach(func() {
sink.Log(lager.LogFormat{
LogLevel: lager.INFO,
Message: "hello world",
Data: lager.Data{"foo": "bar", "dummy": dummyStruct{A: "abcd"}},
})
})
It("writes the data to the given sink without truncating any strings", func() {
Expect(testSink.Buffer().Contents()).To(
MatchJSON(`{"timestamp":"","log_level":1,"source":"","message":"hello world","data":{"foo":"bar","dummy":{"A":"abcd"}}}`),
)
})
})
Context("when given data that includes strings that exceed the configured max length", func() {
BeforeEach(func() {
sink.Log(lager.LogFormat{
LogLevel: lager.INFO,
Message: "hello world",
Data: lager.Data{"foo": longString, "dummy": dummyStruct{A: longString}},
})
})
It("truncates the data and writes to the given sink", func() {
Expect(testSink.Buffer().Contents()).To(
MatchJSON(`{"timestamp":"","log_level":1,"source":"","message":"hello world","data":{"foo":"aaaaaaaa-(truncated)","dummy":{"A":"aaaaaaaa-(truncated)"}}}`),
)
})
})
})