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

Function TestSugarConcatenatingLogging

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

Source from the content-addressed store, hash-verified

326}
327
328func TestSugarConcatenatingLogging(t *testing.T) {
329 tests := []struct {
330 args []interface{}
331 expect string
332 }{
333 {[]interface{}{nil}, "<nil>"},
334 }
335
336 // Common to all test cases.
337 context := []interface{}{"foo", "bar"}
338 expectedFields := []Field{String("foo", "bar")}
339
340 for _, tt := range tests {
341 withSugar(t, DebugLevel, nil, func(logger *SugaredLogger, logs *observer.ObservedLogs) {
342 logger.With(context...).Debug(tt.args...)
343 logger.With(context...).Info(tt.args...)
344 logger.With(context...).Warn(tt.args...)
345 logger.With(context...).Error(tt.args...)
346 logger.With(context...).DPanic(tt.args...)
347 logger.With(context...).Log(InfoLevel, tt.args...)
348
349 expected := make([]observer.LoggedEntry, 6)
350 for i, lvl := range []zapcore.Level{DebugLevel, InfoLevel, WarnLevel, ErrorLevel, DPanicLevel, InfoLevel} {
351 expected[i] = observer.LoggedEntry{
352 Entry: zapcore.Entry{Message: tt.expect, Level: lvl},
353 Context: expectedFields,
354 }
355 }
356 assert.Equal(t, expected, logs.AllUntimed(), "Unexpected log output.")
357 })
358 }
359}
360
361func TestSugarTemplatedLogging(t *testing.T) {
362 tests := []struct {

Callers

nothing calls this directly

Calls 10

StringFunction · 0.85
withSugarFunction · 0.85
AllUntimedMethod · 0.80
WithMethod · 0.65
DebugMethod · 0.45
InfoMethod · 0.45
WarnMethod · 0.45
ErrorMethod · 0.45
DPanicMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected