(t *testing.T)
| 156 | } |
| 157 | |
| 158 | func 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 | |
| 188 | func TestWithGroup(t *testing.T) { |
| 189 | fac, observedLogs := observer.New(zapcore.DebugLevel) |
nothing calls this directly
no test coverage detected