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

Function TestLevel

log_test.go:729–783  ·  log_test.go::TestLevel
(t *testing.T)

Source from the content-addressed store, hash-verified

727}
728
729func TestLevel(t *testing.T) {
730 t.Run("Disabled", func(t *testing.T) {
731 out := &bytes.Buffer{}
732 log := New(out).Level(Disabled)
733 log.Info().Msg("test")
734 if got, want := decodeIfBinaryToString(out.Bytes()), ""; got != want {
735 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
736 }
737 })
738
739 t.Run("NoLevel/Disabled", func(t *testing.T) {
740 out := &bytes.Buffer{}
741 log := New(out).Level(Disabled)
742 log.Log().Msg("test")
743 if got, want := decodeIfBinaryToString(out.Bytes()), ""; got != want {
744 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
745 }
746 })
747
748 t.Run("NoLevel/Info", func(t *testing.T) {
749 out := &bytes.Buffer{}
750 log := New(out).Level(InfoLevel)
751 log.Log().Msg("test")
752 if got, want := decodeIfBinaryToString(out.Bytes()), `{"message":"test"}`+"\n"; got != want {
753 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
754 }
755 })
756
757 t.Run("NoLevel/Panic", func(t *testing.T) {
758 out := &bytes.Buffer{}
759 log := New(out).Level(PanicLevel)
760 log.Log().Msg("test")
761 if got, want := decodeIfBinaryToString(out.Bytes()), `{"message":"test"}`+"\n"; got != want {
762 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
763 }
764 })
765
766 t.Run("NoLevel/WithLevel", func(t *testing.T) {
767 out := &bytes.Buffer{}
768 log := New(out).Level(InfoLevel)
769 log.WithLevel(NoLevel).Msg("test")
770 if got, want := decodeIfBinaryToString(out.Bytes()), `{"message":"test"}`+"\n"; got != want {
771 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
772 }
773 })
774
775 t.Run("Info", func(t *testing.T) {
776 out := &bytes.Buffer{}
777 log := New(out).Level(InfoLevel)
778 log.Info().Msg("test")
779 if got, want := decodeIfBinaryToString(out.Bytes()), `{"level":"info","message":"test"}`+"\n"; got != want {
780 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
781 }
782 })
783}
784
785func TestGetLevel(t *testing.T) {
786 levels := []Level{

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
LevelMethod · 0.80
MsgMethod · 0.80
WithLevelMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
RunMethod · 0.65
InfoMethod · 0.65
LogMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected