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

Function TestEventTimestamp

log_test.go:1102–1116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1100}
1101
1102func TestEventTimestamp(t *testing.T) {
1103 TimestampFunc = func() time.Time {
1104 return time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC)
1105 }
1106 defer func() {
1107 TimestampFunc = time.Now
1108 }()
1109 out := &bytes.Buffer{}
1110 log := New(out).With().Str("foo", "bar").Logger()
1111 log.Log().Timestamp().Msg("hello world")
1112
1113 if got, want := decodeIfBinaryToString(out.Bytes()), `{"foo":"bar","time":"2001-02-03T04:05:06Z","message":"hello world"}`+"\n"; got != want {
1114 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
1115 }
1116}
1117
1118func TestOutputWithoutTimestamp(t *testing.T) {
1119 ignoredOut := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
LogMethod · 0.65
StrMethod · 0.45
TimestampMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected