| 66 | } |
| 67 | |
| 68 | func 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 | |
| 95 | func TestWriterSplitsMax64KB(t *testing.T) { |
| 96 | buf := &bufferWithMu{ |