MCPcopy
hub / github.com/uber-go/zap / TestLevelText

Function TestLevelText

zapcore/level_test.go:51–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestLevelText(t *testing.T) {
52 tests := []struct {
53 text string
54 level Level
55 }{
56 {"debug", DebugLevel},
57 {"info", InfoLevel},
58 {"", InfoLevel}, // make the zero value useful
59 {"warn", WarnLevel},
60 {"error", ErrorLevel},
61 {"dpanic", DPanicLevel},
62 {"panic", PanicLevel},
63 {"fatal", FatalLevel},
64 }
65 for _, tt := range tests {
66 if tt.text != "" {
67 lvl := tt.level
68 marshaled, err := lvl.MarshalText()
69 assert.NoError(t, err, "Unexpected error marshaling level %v to text.", &lvl)
70 assert.Equal(t, tt.text, string(marshaled), "Marshaling level %v to text yielded unexpected result.", &lvl)
71 }
72
73 var unmarshaled Level
74 err := unmarshaled.UnmarshalText([]byte(tt.text))
75 assert.NoError(t, err, `Unexpected error unmarshaling text %q to level.`, tt.text)
76 assert.Equal(t, tt.level, unmarshaled, `Text %q unmarshaled to an unexpected level.`, tt.text)
77 }
78
79 // Some logging libraries are using "warning" instead of "warn" as level indicator. Handle this case
80 // for cross compatibility.
81 t.Run("unmarshal warning compatibility", func(t *testing.T) {
82 var unmarshaled Level
83 input := []byte("warning")
84 err := unmarshaled.UnmarshalText(input)
85 assert.NoError(t, err, `Unexpected error unmarshaling text %q to level.`, string(input))
86 assert.Equal(t, WarnLevel, unmarshaled, `Text %q unmarshaled to an unexpected level.`, string(input))
87 })
88}
89
90func TestParseLevel(t *testing.T) {
91 tests := []struct {

Callers

nothing calls this directly

Calls 2

UnmarshalTextMethod · 0.95
MarshalTextMethod · 0.45

Tested by

no test coverage detected