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.
14 func checkWrite(t
*testing
.T
, w io
.Writer
, data
[]byte, c
chan int) {
15 n
, err
:= w
.Write(data
)
17 t
.Errorf("write: %v", err
)
20 t
.Errorf("short write: %d != %d", n
, len(data
))
25 func checkRead(t
*testing
.T
, r io
.Reader
, data
[]byte, wantErr os
.Error
) {
26 buf
:= make([]byte, len(data
)+10)
29 t
.Errorf("read: %v", err
)
32 if n
!= len(data
) ||
!bytes
.Equal(buf
[0:n
], data
) {
33 t
.Errorf("bad read: got %q", buf
[0:n
])
38 // Test a simple read/write/close sequence.
39 // Assumes that the underlying io.Pipe implementation
40 // is solid and we're just testing the net wrapping.
42 func TestPipe(t
*testing
.T
) {
45 go checkWrite(t
, cli
, []byte("hello, world"), c
)
46 checkRead(t
, srv
, []byte("hello, world"), nil)
48 go checkWrite(t
, srv
, []byte("line 2"), c
)
49 checkRead(t
, cli
, []byte("line 2"), nil)
51 go checkWrite(t
, cli
, []byte("a third line"), c
)
52 checkRead(t
, srv
, []byte("a third line"), nil)
55 checkRead(t
, cli
, nil, os
.EOF
)