MCPcopy
hub / github.com/rs/zerolog / TestSlogHandler_HandlePropagatesContext

Function TestSlogHandler_HandlePropagatesContext

slog_test.go:499–521  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

497}
498
499func TestSlogHandler_HandlePropagatesContext(t *testing.T) {
500 var buf bytes.Buffer
501 type ctxKey struct{}
502 ctx := context.WithValue(context.Background(), ctxKey{}, "test-value")
503
504 var gotCtx context.Context
505 hook := zerolog.HookFunc(func(e *zerolog.Event, level zerolog.Level, msg string) {
506 gotCtx = e.GetCtx()
507 })
508
509 zl := zerolog.New(&buf).Hook(hook)
510 handler := zerolog.NewSlogHandler(zl)
511
512 record := slog.NewRecord(time.Now(), slog.LevelInfo, "test", 0)
513 _ = handler.Handle(ctx, record)
514
515 if gotCtx == nil {
516 t.Fatal("expected context to be propagated to event")
517 }
518 if gotCtx.Value(ctxKey{}) != "test-value" {
519 t.Error("expected context value to be preserved")
520 }
521}
522
523func TestSlogHandler_NoDuplicateTimestamp(t *testing.T) {
524 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 8

HandleMethod · 0.95
HookFuncFuncType · 0.92
NewFunction · 0.92
NewSlogHandlerFunction · 0.92
GetCtxMethod · 0.80
HookMethod · 0.80
FatalMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…