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

49 lines
836 B

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