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

Function TestWriterSplitNewlines

writer_test.go:68–93  ·  writer_test.go::TestWriterSplitNewlines
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestWriterSplitNewlines(t *testing.T) {
69 buf := &bufferWithMu{
70 buf: bytes.NewBuffer(nil),
71 }
72 logger := logrus.New()
73 logger.Formatter = &logrus.TextFormatter{
74 DisableColors: true,
75 DisableTimestamp: true,
76 }
77 logger.SetOutput(buf)
78 writer := logger.Writer()
79
80 const logNum = 10
81
82 for i := 0; i < logNum; i++ {
83 _, err := writer.Write([]byte("bar\nfoo\n"))
84 require.NoError(t, err, "writer.Write failed")
85 }
86 writer.Close()
87 // Test is flaky because it writes in another goroutine,
88 // we need to make sure to wait a bit so all write are done.
89 time.Sleep(500 * time.Millisecond)
90
91 lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
92 assert.Len(t, lines, logNum*2, "logger printed incorrect number of lines")
93}
94
95func TestWriterSplitsMax64KB(t *testing.T) {
96 buf := &bufferWithMu{

Callers

nothing calls this directly

Calls 5

StringMethod · 0.95
NewFunction · 0.92
SetOutputMethod · 0.80
WriterMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected