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

Function TestAtomicLevelText

level_test.go:101–140  ·  level_test.go::TestAtomicLevelText
(t *testing.T)

Source from the content-addressed store, hash-verified

99}
100
101func TestAtomicLevelText(t *testing.T) {
102 tests := []struct {
103 text string
104 expect zapcore.Level
105 err bool
106 }{
107 {"debug", DebugLevel, false},
108 {"info", InfoLevel, false},
109 {"", InfoLevel, false},
110 {"warn", WarnLevel, false},
111 {"error", ErrorLevel, false},
112 {"dpanic", DPanicLevel, false},
113 {"panic", PanicLevel, false},
114 {"fatal", FatalLevel, false},
115 {"foobar", InfoLevel, true},
116 }
117
118 for _, tt := range tests {
119 var lvl AtomicLevel
120 // Test both initial unmarshaling and overwriting existing value.
121 for i := 0; i < 2; i++ {
122 if tt.err {
123 assert.Error(t, lvl.UnmarshalText([]byte(tt.text)), "Expected unmarshaling %q to fail.", tt.text)
124 } else {
125 assert.NoError(t, lvl.UnmarshalText([]byte(tt.text)), "Expected unmarshaling %q to succeed.", tt.text)
126 }
127 assert.Equal(t, tt.expect, lvl.Level(), "Unexpected level after unmarshaling.")
128 lvl.SetLevel(InfoLevel)
129 }
130
131 // Test marshalling
132 if tt.text != "" && !tt.err {
133 lvl.SetLevel(tt.expect)
134 marshaled, err := lvl.MarshalText()
135 assert.NoError(t, err, `Unexpected error marshalling level "%v" to text.`, tt.expect)
136 assert.Equal(t, tt.text, string(marshaled), "Expected marshaled text to match")
137 assert.Equal(t, tt.text, lvl.String(), "Expected Stringer call to match")
138 }
139 }
140}

Callers

nothing calls this directly

Calls 6

UnmarshalTextMethod · 0.95
LevelMethod · 0.95
SetLevelMethod · 0.95
MarshalTextMethod · 0.95
StringMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected