1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-20 03:16:24 -05:00
v2fly/transport/ray/direct_test.go

49 lines
836 B
Go
Raw Normal View History

2016-12-22 11:28:06 -05:00
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()
2016-12-26 18:44:11 -05:00
b1 := buf.New()
b1.AppendBytes('a')
assert.Error(stream.Write(b1)).IsNil()
2016-12-22 11:28:06 -05:00
_, err := stream.Read()
assert.Error(err).IsNil()
stream.Close()
_, err = stream.Read()
assert.Error(err).Equals(io.EOF)
2016-12-26 18:44:11 -05:00
b2 := buf.New()
b2.AppendBytes('b')
err = stream.Write(b2)
2016-12-22 11:28:06 -05:00
assert.Error(err).Equals(io.ErrClosedPipe)
}
func TestStreamClose(t *testing.T) {
assert := assert.On(t)
stream := NewStream()
2016-12-26 18:44:11 -05:00
b1 := buf.New()
b1.AppendBytes('a')
assert.Error(stream.Write(b1)).IsNil()
2016-12-22 11:28:06 -05:00
stream.Close()
_, err := stream.Read()
assert.Error(err).IsNil()
_, err = stream.Read()
assert.Error(err).Equals(io.EOF)
}