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

Function TestSlogHandler_TimestampWithoutHook

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

Source from the content-addressed store, hash-verified

543}
544
545func TestSlogHandler_TimestampWithoutHook(t *testing.T) {
546 var buf bytes.Buffer
547 // Logger without Timestamp() hook - Handle should add the timestamp
548 zl := zerolog.New(&buf)
549 handler := zerolog.NewSlogHandler(zl)
550
551 ts := time.Date(2024, 6, 15, 12, 0, 0, 0, time.UTC)
552 record := slog.NewRecord(ts, slog.LevelInfo, "test", 0)
553 _ = handler.Handle(context.Background(), record)
554
555 m := decodeJSON(t, &buf)
556 if m[zerolog.TimestampFieldName] == nil {
557 t.Error("expected timestamp field when logger has no timestamp hook")
558 }
559}

Callers

nothing calls this directly

Calls 5

HandleMethod · 0.95
NewFunction · 0.92
NewSlogHandlerFunction · 0.92
decodeJSONFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected