(t *testing.T)
| 227 | } |
| 228 | |
| 229 | func TestLogHandler_WithGroup(t *testing.T) { |
| 230 | var buf bytes.Buffer |
| 231 | |
| 232 | opts := &slog.HandlerOptions{ |
| 233 | Level: slog.LevelInfo, |
| 234 | ReplaceAttr: ReplaceAttr, |
| 235 | } |
| 236 | baseHandler := slog.NewJSONHandler(&buf, opts) |
| 237 | handler := &lambdaHandler{handler: baseHandler} |
| 238 | |
| 239 | lc := &LambdaContext{AwsRequestID: "test-request"} |
| 240 | ctx := NewContext(context.Background(), lc) |
| 241 | |
| 242 | logger := slog.New(handler).WithGroup("app").With("version", "1.0") |
| 243 | logger.InfoContext(ctx, "test message") |
| 244 | |
| 245 | var logOutput map[string]interface{} |
| 246 | err := json.Unmarshal(buf.Bytes(), &logOutput) |
| 247 | require.NoError(t, err) |
| 248 | |
| 249 | app, ok := logOutput["app"].(map[string]interface{}) |
| 250 | require.True(t, ok, "expected 'app' group in output: %s", buf.String()) |
| 251 | assert.Equal(t, "1.0", app["version"]) |
| 252 | assert.Equal(t, "test-request", app["requestId"]) |
| 253 | } |
| 254 | |
| 255 | func TestLogHandler_WithFields(t *testing.T) { |
| 256 | var buf bytes.Buffer |
nothing calls this directly
no test coverage detected
searching dependent graphs…