1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func checkPipeWrite(t
*testing
.T
, w io
.Writer
, data
[]byte, c
chan int) {
14 n
, err
:= w
.Write(data
)
19 t
.Errorf("short write: %d != %d", n
, len(data
))
24 func checkPipeRead(t
*testing
.T
, r io
.Reader
, data
[]byte, wantErr error
) {
25 buf
:= make([]byte, len(data
)+10)
31 if n
!= len(data
) ||
!bytes
.Equal(buf
[0:n
], data
) {
32 t
.Errorf("bad read: got %q", buf
[0:n
])
37 // TestPipe tests a simple read/write/close sequence.
38 // Assumes that the underlying io.Pipe implementation
39 // is solid and we're just testing the net wrapping.
40 func TestPipe(t
*testing
.T
) {
43 go checkPipeWrite(t
, cli
, []byte("hello, world"), c
)
44 checkPipeRead(t
, srv
, []byte("hello, world"), nil)
46 go checkPipeWrite(t
, srv
, []byte("line 2"), c
)
47 checkPipeRead(t
, cli
, []byte("line 2"), nil)
49 go checkPipeWrite(t
, cli
, []byte("a third line"), c
)
50 checkPipeRead(t
, srv
, []byte("a third line"), nil)
53 checkPipeRead(t
, cli
, nil, io
.EOF
)