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

Function TestLogHandler_FieldsEmpty

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

Source from the content-addressed store, hash-verified

327}
328
329func TestLogHandler_FieldsEmpty(t *testing.T) {
330 var buf bytes.Buffer
331
332 opts := &slog.HandlerOptions{
333 Level: slog.LevelInfo,
334 ReplaceAttr: ReplaceAttr,
335 }
336 baseHandler := slog.NewJSONHandler(&buf, opts)
337
338 options := &logOptions{}
339 WithFunctionARN()(options)
340 WithTenantID()(options)
341
342 handler := &lambdaHandler{
343 handler: baseHandler,
344 fields: options.fields,
345 }
346
347 lc := &LambdaContext{
348 AwsRequestID: "test-request-123",
349 InvokedFunctionArn: "",
350 TenantID: "",
351 }
352 ctx := NewContext(context.Background(), lc)
353
354 logger := slog.New(handler)
355 logger.InfoContext(ctx, "test message")
356
357 var logOutput map[string]interface{}
358 err := json.Unmarshal(buf.Bytes(), &logOutput)
359 require.NoError(t, err)
360
361 assert.Equal(t, "test-request-123", logOutput["requestId"])
362 assert.NotContains(t, logOutput, "functionArn")
363 assert.NotContains(t, logOutput, "tenantId")
364}
365
366func TestWithFunctionARN(t *testing.T) {
367 options := &logOptions{}

Callers

nothing calls this directly

Calls 3

WithFunctionARNFunction · 0.85
WithTenantIDFunction · 0.85
NewContextFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…