mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
76212635b5
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
34 lines
684 B
Go
34 lines
684 B
Go
package ioutils
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"io/ioutil"
|
|
"testing"
|
|
)
|
|
|
|
func TestBufReader(t *testing.T) {
|
|
reader, writer := io.Pipe()
|
|
bufreader := NewBufReader(reader)
|
|
|
|
// Write everything down to a Pipe
|
|
// Usually, a pipe should block but because of the buffered reader,
|
|
// the writes will go through
|
|
done := make(chan bool)
|
|
go func() {
|
|
writer.Write([]byte("hello world"))
|
|
writer.Close()
|
|
done <- true
|
|
}()
|
|
|
|
// Drain the reader *after* everything has been written, just to verify
|
|
// it is indeed buffering
|
|
<-done
|
|
output, err := ioutil.ReadAll(bufreader)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(output, []byte("hello world")) {
|
|
t.Error(string(output))
|
|
}
|
|
}
|