(t *testing.T)
| 253 | } |
| 254 | |
| 255 | func TestLogHandler_WithFields(t *testing.T) { |
| 256 | var buf bytes.Buffer |
| 257 | |
| 258 | opts := &slog.HandlerOptions{ |
| 259 | Level: slog.LevelInfo, |
| 260 | ReplaceAttr: ReplaceAttr, |
| 261 | } |
| 262 | baseHandler := slog.NewJSONHandler(&buf, opts) |
| 263 | |
| 264 | // Create options with fields |
| 265 | options := &logOptions{} |
| 266 | WithFunctionARN()(options) |
| 267 | WithTenantID()(options) |
| 268 | |
| 269 | handler := &lambdaHandler{ |
| 270 | handler: baseHandler, |
| 271 | fields: options.fields, |
| 272 | } |
| 273 | |
| 274 | lc := &LambdaContext{ |
| 275 | AwsRequestID: "test-request-123", |
| 276 | InvokedFunctionArn: "arn:aws:lambda:us-east-1:123456789:function:test", |
| 277 | TenantID: "tenant-abc", |
| 278 | } |
| 279 | ctx := NewContext(context.Background(), lc) |
| 280 | |
| 281 | logger := slog.New(handler) |
| 282 | logger.InfoContext(ctx, "test message") |
| 283 | |
| 284 | var logOutput map[string]interface{} |
| 285 | err := json.Unmarshal(buf.Bytes(), &logOutput) |
| 286 | require.NoError(t, err) |
| 287 | |
| 288 | assert.Equal(t, "test-request-123", logOutput["requestId"]) |
| 289 | assert.Equal(t, "arn:aws:lambda:us-east-1:123456789:function:test", logOutput["functionArn"]) |
| 290 | assert.Equal(t, "tenant-abc", logOutput["tenantId"]) |
| 291 | } |
| 292 | |
| 293 | func TestLogHandler_WithFieldFunctionARNOnly(t *testing.T) { |
| 294 | var buf bytes.Buffer |
nothing calls this directly
no test coverage detected
searching dependent graphs…