1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/transport/internet/kcp/connection_test.go
2017-12-14 23:24:40 +01:00

43 lines
904 B
Go

package kcp_test
import (
"io"
"testing"
"time"
"v2ray.com/core/common/buf"
. "v2ray.com/core/transport/internet/kcp"
. "v2ray.com/ext/assert"
)
type NoOpCloser int
func (NoOpCloser) Close() error {
return nil
}
func TestConnectionReadTimeout(t *testing.T) {
assert := With(t)
conn := NewConnection(ConnMetadata{Conversation: 1}, &KCPPacketWriter{
Writer: buf.DiscardBytes,
}, NoOpCloser(0), &Config{})
conn.SetReadDeadline(time.Now().Add(time.Second))
b := make([]byte, 1024)
nBytes, err := conn.Read(b)
assert(nBytes, Equals, 0)
assert(err, IsNotNil)
conn.Terminate()
}
func TestConnectionInterface(t *testing.T) {
assert := With(t)
assert((*Connection)(nil), Implements, (*io.Writer)(nil))
assert((*Connection)(nil), Implements, (*io.Reader)(nil))
assert((*Connection)(nil), Implements, (*buf.Reader)(nil))
assert((*Connection)(nil), Implements, (*buf.Writer)(nil))
}