github.com/dougm/docker@v1.5.0/pkg/ioutils/readers_test.go (about) 1 package ioutils 2 3 import ( 4 "bytes" 5 "io" 6 "io/ioutil" 7 "testing" 8 ) 9 10 func TestBufReader(t *testing.T) { 11 reader, writer := io.Pipe() 12 bufreader := NewBufReader(reader) 13 14 // Write everything down to a Pipe 15 // Usually, a pipe should block but because of the buffered reader, 16 // the writes will go through 17 done := make(chan bool) 18 go func() { 19 writer.Write([]byte("hello world")) 20 writer.Close() 21 done <- true 22 }() 23 24 // Drain the reader *after* everything has been written, just to verify 25 // it is indeed buffering 26 <-done 27 output, err := ioutil.ReadAll(bufreader) 28 if err != nil { 29 t.Fatal(err) 30 } 31 if !bytes.Equal(output, []byte("hello world")) { 32 t.Error(string(output)) 33 } 34 }