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

Function TestIncreaseLevel

increase_level_test.go:68–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestIncreaseLevel(t *testing.T) {
69 errorOut := &bytes.Buffer{}
70 opts := []Option{
71 ErrorOutput(zapcore.AddSync(errorOut)),
72 }
73 withLogger(t, WarnLevel, opts, func(logger *Logger, logs *observer.ObservedLogs) {
74 logger.Warn("original warn log")
75
76 errorLogger := logger.WithOptions(IncreaseLevel(ErrorLevel))
77 errorLogger.Debug("ignored debug log")
78 errorLogger.Warn("ignored warn log")
79 errorLogger.Error("increase level error log")
80
81 withFields := errorLogger.With(String("k", "v"))
82 withFields.Debug("ignored debug log with fields")
83 withFields.Warn("ignored warn log with fields")
84 withFields.Error("increase level error log with fields")
85
86 assert.Equal(t, []observer.LoggedEntry{
87 newLoggedEntry(WarnLevel, "original warn log"),
88 newLoggedEntry(ErrorLevel, "increase level error log"),
89 newLoggedEntry(ErrorLevel, "increase level error log with fields", String("k", "v")),
90 }, logs.AllUntimed(), "unexpected logs")
91
92 assert.Empty(t, errorOut.String(), "expect no error output")
93 })
94}

Callers

nothing calls this directly

Calls 13

StringMethod · 0.95
AddSyncFunction · 0.92
ErrorOutputFunction · 0.85
IncreaseLevelFunction · 0.85
StringFunction · 0.85
newLoggedEntryFunction · 0.85
AllUntimedMethod · 0.80
withLoggerFunction · 0.70
WithMethod · 0.65
WarnMethod · 0.45
WithOptionsMethod · 0.45
DebugMethod · 0.45

Tested by

no test coverage detected