13 // Test that CopyPipeToChildLog works even on lines longer than
14 // bufio.MaxScanTokenSize.
15 func TestCopyPipeToChildLogLongLines(t *testing.T) {
16 logger, logBuf := bufLogger()
18 pipeIn, pipeOut := io.Pipe()
19 copied := make(chan bool)
21 copyPipeToChildLog(pipeIn, logger)
25 sentBytes := make([]byte, bufio.MaxScanTokenSize+MaxLogLine+(1<<22))
27 pipeOut.Write([]byte("before\n"))
29 for i := range sentBytes {
30 // Some bytes that aren't newlines:
31 sentBytes[i] = byte((rand.Int() & 0xff) | 0x80)
33 sentBytes[len(sentBytes)-1] = '\n'
34 pipeOut.Write(sentBytes)
36 pipeOut.Write([]byte("after"))
40 if before, err := logBuf.ReadBytes('\n'); err != nil || string(before) != "before\n" {
41 t.Fatalf("\"before\n\" not received (got \"%s\", %s)", before, err)
44 var receivedBytes []byte
47 line, err := logBuf.ReadBytes('\n')
51 if len(line) >= 5 && string(line[0:5]) == "[...]" {
52 if receivedBytes == nil {
53 t.Fatal("Beginning of line reported as continuation")
57 if len(line) >= 6 && string(line[len(line)-6:]) == "[...]\n" {
58 line = line[:len(line)-6]
62 receivedBytes = append(receivedBytes, line...)
64 if bytes.Compare(receivedBytes, sentBytes) != 0 {
65 t.Fatalf("sent %d bytes, got %d different bytes", len(sentBytes), len(receivedBytes))
68 if after, err := logBuf.ReadBytes('\n'); err != nil || string(after) != "after\n" {
69 t.Fatalf("\"after\n\" not received (got \"%s\", %s)", after, err)
73 case <-time.After(time.Second):
80 func bufLogger() (*log.Logger, *bufio.Reader) {
82 logger := log.New(w, "", 0)
83 return logger, bufio.NewReader(r)