You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/transport/ray/direct_test.go

50 lines
902 B

8 years ago
package ray_test
import (
8 years ago
"context"
8 years ago
"io"
"testing"
"v2ray.com/core/common/buf"
. "v2ray.com/ext/assert"
8 years ago
. "v2ray.com/core/transport/ray"
)
func TestStreamIO(t *testing.T) {
assert := With(t)
8 years ago
stream := NewStream(context.Background())
b1 := buf.New()
b1.AppendBytes('a')
assert(stream.Write(buf.NewMultiBufferValue(b1)), IsNil)
8 years ago
_, err := stream.Read()
assert(err, IsNil)
8 years ago
stream.Close()
_, err = stream.Read()
assert(err, Equals, io.EOF)
8 years ago
b2 := buf.New()
b2.AppendBytes('b')
8 years ago
err = stream.Write(buf.NewMultiBufferValue(b2))
assert(err, Equals, io.ErrClosedPipe)
8 years ago
}
func TestStreamClose(t *testing.T) {
assert := With(t)
8 years ago
stream := NewStream(context.Background())
b1 := buf.New()
b1.AppendBytes('a')
assert(stream.Write(buf.NewMultiBufferValue(b1)), IsNil)
8 years ago
stream.Close()
_, err := stream.Read()
assert(err, IsNil)
8 years ago
_, err = stream.Read()
assert(err, Equals, io.EOF)
8 years ago
}