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

Function TestLevelFieldMarshalFunc

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

Source from the content-addressed store, hash-verified

1191}
1192
1193func TestLevelFieldMarshalFunc(t *testing.T) {
1194 origLevelFieldMarshalFunc := LevelFieldMarshalFunc
1195 LevelFieldMarshalFunc = func(l Level) string {
1196 return strings.ToUpper(l.String())
1197 }
1198 defer func() {
1199 LevelFieldMarshalFunc = origLevelFieldMarshalFunc
1200 }()
1201 out := &bytes.Buffer{}
1202 log := New(out)
1203
1204 log.Debug().Msg("test")
1205 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"DEBUG","message":"test"}`+"\n"; got != want {
1206 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
1207 }
1208 out.Reset()
1209
1210 log.Info().Msg("test")
1211 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"INFO","message":"test"}`+"\n"; got != want {
1212 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
1213 }
1214 out.Reset()
1215
1216 log.Warn().Msg("test")
1217 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"WARN","message":"test"}`+"\n"; got != want {
1218 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
1219 }
1220 out.Reset()
1221
1222 log.Error().Msg("test")
1223 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"ERROR","message":"test"}`+"\n"; got != want {
1224 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
1225 }
1226 out.Reset()
1227}
1228
1229type errWriter struct {
1230 error

Callers

nothing calls this directly

Calls 10

NewFunction · 0.85
MsgMethod · 0.80
ResetMethod · 0.80
WarnMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
DebugMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45
BytesMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected