(t *testing.T)
| 497 | } |
| 498 | |
| 499 | func 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 | |
| 523 | func TestSlogHandler_NoDuplicateTimestamp(t *testing.T) { |
| 524 | var buf bytes.Buffer |
nothing calls this directly
no test coverage detected
searching dependent graphs…