MCPcopy
hub / github.com/uber-go/zap / TestObserverWith

Function TestObserverWith

zaptest/observer/observer_test.go:76–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestObserverWith(t *testing.T) {
77 sf1, logs := New(zap.InfoLevel)
78
79 // need to pad out enough initial fields so that the underlying slice cap()
80 // gets ahead of its len() so that the sf3/4 With append's could choose
81 // not to copy (if the implementation doesn't force them)
82 sf1 = sf1.With([]zapcore.Field{zap.Int("a", 1), zap.Int("b", 2)})
83
84 sf2 := sf1.With([]zapcore.Field{zap.Int("c", 3)})
85 sf3 := sf2.With([]zapcore.Field{zap.Int("d", 4)})
86 sf4 := sf2.With([]zapcore.Field{zap.Int("e", 5)})
87 ent := zapcore.Entry{Level: zap.InfoLevel, Message: "hello"}
88
89 for i, core := range []zapcore.Core{sf2, sf3, sf4} {
90 if ce := core.Check(ent, nil); ce != nil {
91 ce.Write(zap.Int("i", i))
92 }
93 }
94
95 assert.Equal(t, []LoggedEntry{
96 {
97 Entry: ent,
98 Context: []zapcore.Field{
99 zap.Int("a", 1),
100 zap.Int("b", 2),
101 zap.Int("c", 3),
102 zap.Int("i", 0),
103 },
104 },
105 {
106 Entry: ent,
107 Context: []zapcore.Field{
108 zap.Int("a", 1),
109 zap.Int("b", 2),
110 zap.Int("c", 3),
111 zap.Int("d", 4),
112 zap.Int("i", 1),
113 },
114 },
115 {
116 Entry: ent,
117 Context: []zapcore.Field{
118 zap.Int("a", 1),
119 zap.Int("b", 2),
120 zap.Int("c", 3),
121 zap.Int("e", 5),
122 zap.Int("i", 2),
123 },
124 },
125 }, logs.All(), "expected no field sharing between With siblings")
126}
127
128func TestFilters(t *testing.T) {
129 logs := []LoggedEntry{

Callers

nothing calls this directly

Calls 6

IntFunction · 0.92
AllMethod · 0.80
NewFunction · 0.70
WithMethod · 0.65
CheckMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected