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

Function TestInlineGroup

exp/zapslog/handler_test.go:158–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestInlineGroup(t *testing.T) {
159 fac, observedLogs := observer.New(zapcore.DebugLevel)
160
161 t.Run("simple", func(t *testing.T) {
162 sl := slog.New(NewHandler(fac))
163 sl.Info("msg", "a", "b", slog.Group("", slog.String("c", "d")), "e", "f")
164
165 logs := observedLogs.TakeAll()
166 require.Len(t, logs, 1, "Expected exactly one entry to be logged")
167 assert.Equal(t, map[string]any{
168 "a": "b",
169 "c": "d",
170 "e": "f",
171 }, logs[0].ContextMap(), "Unexpected context")
172 })
173
174 t.Run("recursive", func(t *testing.T) {
175 sl := slog.New(NewHandler(fac))
176 sl.Info("msg", "a", "b", slog.Group("", slog.Group("", slog.Group("", slog.String("c", "d"))), slog.Group("", "e", "f")))
177
178 logs := observedLogs.TakeAll()
179 require.Len(t, logs, 1, "Expected exactly one entry to be logged")
180 assert.Equal(t, map[string]any{
181 "a": "b",
182 "c": "d",
183 "e": "f",
184 }, logs[0].ContextMap(), "Unexpected context")
185 })
186}
187
188func TestWithGroup(t *testing.T) {
189 fac, observedLogs := observer.New(zapcore.DebugLevel)

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
NewHandlerFunction · 0.85
TakeAllMethod · 0.80
ContextMapMethod · 0.80
InfoMethod · 0.45
StringMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected