v2ray-core/transport/ray/direct_test.go

50 lines
962 B
Go
Raw Normal View History

2016-12-22 16:28:06 +00:00
package ray_test
import (
2017-04-13 20:17:58 +00:00
"context"
2016-12-22 16:28:06 +00:00
"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(context.Background())
2016-12-26 23:44:11 +00:00
b1 := buf.New()
b1.AppendBytes('a')
2017-04-15 19:07:23 +00:00
assert.Error(stream.Write(buf.NewMultiBufferValue(b1))).IsNil()
2016-12-22 16:28:06 +00:00
_, err := stream.Read()
assert.Error(err).IsNil()
stream.Close()
_, err = stream.Read()
assert.Error(err).Equals(io.EOF)
2016-12-26 23:44:11 +00:00
b2 := buf.New()
b2.AppendBytes('b')
2017-04-15 19:07:23 +00:00
err = stream.Write(buf.NewMultiBufferValue(b2))
2016-12-22 16:28:06 +00:00
assert.Error(err).Equals(io.ErrClosedPipe)
}
func TestStreamClose(t *testing.T) {
assert := assert.On(t)
stream := NewStream(context.Background())
2016-12-26 23:44:11 +00:00
b1 := buf.New()
b1.AppendBytes('a')
2017-04-15 19:07:23 +00:00
assert.Error(stream.Write(buf.NewMultiBufferValue(b1))).IsNil()
2016-12-22 16:28:06 +00:00
stream.Close()
_, err := stream.Read()
assert.Error(err).IsNil()
_, err = stream.Read()
assert.Error(err).Equals(io.EOF)
}