-
Notifications
You must be signed in to change notification settings - Fork 28
/
redacting_sink_test.go
62 lines (51 loc) · 1.62 KB
/
redacting_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
package lager_test
import (
"encoding/json"
"code.cloudfoundry.org/lager/v3"
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("RedactingSink", func() {
var (
sink lager.Sink
testSink *lagertest.TestSink
)
BeforeEach(func() {
testSink = lagertest.NewTestSink()
var err error
sink, err = lager.NewRedactingSink(testSink, nil, nil)
Expect(err).NotTo(HaveOccurred())
})
Context("when given a valid set of data", func() {
BeforeEach(func() {
sink.Log(lager.LogFormat{
LogLevel: lager.INFO,
Message: "hello world",
Data: lager.Data{"password": "abcd"},
})
})
It("writes to the given sink", func() {
Expect(testSink.Buffer().Contents()).To(MatchJSON(`{"timestamp":"","log_level":1,"source":"","message":"hello world","data":{"password":"*REDACTED*"}}`))
})
})
Context("when an unserializable data object is passed in", func() {
BeforeEach(func() {
sink.Log(lager.LogFormat{
LogLevel: lager.INFO,
Message: "hello world", Data: map[string]interface{}{
"some_key": func() {},
},
})
})
It("logs the serialization error", func() {
message := map[string]interface{}{}
err := json.Unmarshal(testSink.Buffer().Contents(), &message)
Expect(err).NotTo(HaveOccurred())
Expect(message["message"]).To(Equal("hello world"))
Expect(message["log_level"]).To(Equal(float64(1)))
Expect(message["data"].(map[string]interface{})["lager serialisation error"]).To(Equal("json: unsupported type: func()"))
Expect(message["data"].(map[string]interface{})["data_dump"]).ToNot(BeEmpty())
})
})
})