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

Function TestSugarWithCaptures

sugar_test.go:165–239  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestSugarWithCaptures(t *testing.T) {
166 type withAny func(*SugaredLogger, ...interface{}) *SugaredLogger
167
168 tests := []struct {
169 name string
170 withMethods []withAny
171 wantJSON []string
172 }{
173 {
174 name: "with captures arguments at time of With",
175 withMethods: []withAny{(*SugaredLogger).With},
176 wantJSON: []string{
177 `{
178 "m": "hello 0",
179 "a0": [0],
180 "b0": [1]
181 }`,
182 `{
183 "m": "world 0",
184 "a0": [0],
185 "c0": [2]
186 }`,
187 },
188 },
189 {
190 name: "lazy with captures arguments at time of Logging",
191 withMethods: []withAny{(*SugaredLogger).WithLazy},
192 wantJSON: []string{
193 `{
194 "m": "hello 0",
195 "a0": [1],
196 "b0": [1]
197 }`,
198 `{
199 "m": "world 0",
200 "a0": [1],
201 "c0": [2]
202 }`,
203 },
204 },
205 }
206
207 for _, tt := range tests {
208 t.Run(tt.name, func(t *testing.T) {
209 enc := zapcore.NewJSONEncoder(zapcore.EncoderConfig{
210 MessageKey: "m",
211 })
212
213 var bs ztest.Buffer
214 logger := New(zapcore.NewCore(enc, &bs, DebugLevel)).Sugar()
215
216 for i, withMethod := range tt.withMethods {
217 iStr := strconv.Itoa(i)
218 x := 10 * i
219 arr := zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error {
220 enc.AppendInt(x)
221 return nil
222 })

Callers

nothing calls this directly

Calls 10

LinesMethod · 0.95
NewJSONEncoderFunction · 0.92
NewCoreFunction · 0.92
ArrayMarshalerFuncFuncType · 0.92
ArrayFunction · 0.85
SugarMethod · 0.80
InfowMethod · 0.80
NewFunction · 0.70
AppendIntMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected