MCPcopy
hub / github.com/aws/aws-lambda-go / TestLogHandler_WithFieldFunctionARNOnly

Function TestLogHandler_WithFieldFunctionARNOnly

lambdacontext/logger_test.go:293–327  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

291}
292
293func TestLogHandler_WithFieldFunctionARNOnly(t *testing.T) {
294 var buf bytes.Buffer
295
296 opts := &slog.HandlerOptions{
297 Level: slog.LevelInfo,
298 ReplaceAttr: ReplaceAttr,
299 }
300 baseHandler := slog.NewJSONHandler(&buf, opts)
301
302 options := &logOptions{}
303 WithFunctionARN()(options)
304
305 handler := &lambdaHandler{
306 handler: baseHandler,
307 fields: options.fields,
308 }
309
310 lc := &LambdaContext{
311 AwsRequestID: "test-request-123",
312 InvokedFunctionArn: "arn:aws:lambda:us-east-1:123456789:function:test",
313 TenantID: "tenant-abc",
314 }
315 ctx := NewContext(context.Background(), lc)
316
317 logger := slog.New(handler)
318 logger.InfoContext(ctx, "test message")
319
320 var logOutput map[string]interface{}
321 err := json.Unmarshal(buf.Bytes(), &logOutput)
322 require.NoError(t, err)
323
324 assert.Equal(t, "test-request-123", logOutput["requestId"])
325 assert.Equal(t, "arn:aws:lambda:us-east-1:123456789:function:test", logOutput["functionArn"])
326 assert.NotContains(t, logOutput, "tenantId")
327}
328
329func TestLogHandler_FieldsEmpty(t *testing.T) {
330 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 2

WithFunctionARNFunction · 0.85
NewContextFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…