MCPcopy
hub / github.com/sirupsen/logrus / TestPadLevelText

Function TestPadLevelText

text_formatter_test.go:199–288  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

197}
198
199func TestPadLevelText(t *testing.T) {
200 // A note for future maintainers / committers:
201 //
202 // This test denormalizes the level text as a part of its assertions.
203 // Because of that, its not really a "unit test" of the PadLevelText functionality.
204 // So! Many apologies to the potential future person who has to rewrite this test
205 // when they are changing some completely unrelated functionality.
206 params := []struct {
207 name string
208 level Level
209 paddedLevelText string
210 }{
211 {
212 name: "PanicLevel",
213 level: PanicLevel,
214 paddedLevelText: "PANIC ", // 2 extra spaces
215 },
216 {
217 name: "FatalLevel",
218 level: FatalLevel,
219 paddedLevelText: "FATAL ", // 2 extra spaces
220 },
221 {
222 name: "ErrorLevel",
223 level: ErrorLevel,
224 paddedLevelText: "ERROR ", // 2 extra spaces
225 },
226 {
227 name: "WarnLevel",
228 level: WarnLevel,
229 // WARNING is already the max length, so we don't need to assert a paddedLevelText
230 },
231 {
232 name: "DebugLevel",
233 level: DebugLevel,
234 paddedLevelText: "DEBUG ", // 2 extra spaces
235 },
236 {
237 name: "TraceLevel",
238 level: TraceLevel,
239 paddedLevelText: "TRACE ", // 2 extra spaces
240 },
241 {
242 name: "InfoLevel",
243 level: InfoLevel,
244 paddedLevelText: "INFO ", // 3 extra spaces
245 },
246 }
247
248 // We create a "default" TextFormatter to do a control test.
249 // We also create a TextFormatter with PadLevelText, which is the parameter we want to do our most relevant assertions against.
250 tfDefault := TextFormatter{}
251 tfWithPadding := TextFormatter{PadLevelText: true}
252
253 for _, val := range params {
254 t.Run(val.name, func(t *testing.T) {
255 // TextFormatter writes into these bytes.Buffers, and we make assertions about their contents later
256 var bytesDefault bytes.Buffer

Callers

nothing calls this directly

Calls 4

initMethod · 0.95
printColoredMethod · 0.95
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected