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

Function TestWriterSplitsMax64KB

writer_test.go:95–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestWriterSplitsMax64KB(t *testing.T) {
96 buf := &bufferWithMu{
97 buf: bytes.NewBuffer(nil),
98 }
99 logger := logrus.New()
100 logger.Formatter = &logrus.TextFormatter{
101 DisableColors: true,
102 DisableTimestamp: true,
103 }
104 logger.SetOutput(buf)
105 writer := logger.Writer()
106
107 // write more than 64KB
108 const bigWriteLen = bufio.MaxScanTokenSize + 100
109 output := make([]byte, bigWriteLen)
110 // lets not write zero bytes
111 for i := 0; i < bigWriteLen; i++ {
112 output[i] = 'A'
113 }
114
115 for i := 0; i < 3; i++ {
116 len, err := writer.Write(output)
117 require.NoError(t, err, "writer.Write failed")
118 assert.Equal(t, bigWriteLen, len, "bytes written")
119 }
120 writer.Close()
121 // Test is flaky because it writes in another goroutine,
122 // we need to make sure to wait a bit so all write are done.
123 time.Sleep(500 * time.Millisecond)
124
125 lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
126 // we should have 4 lines because we wrote more than 64 KB each time
127 assert.Len(t, lines, 4, "logger printed incorrect number of lines")
128}

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