mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-04 01:06:30 -05:00
test case for writer creation
This commit is contained in:
parent
f27a381fe8
commit
e343fe80a2
50
common/buf/io_test.go
Normal file
50
common/buf/io_test.go
Normal file
@ -0,0 +1,50 @@
|
||||
package buf_test
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
. "v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/testing/servers/tcp"
|
||||
)
|
||||
|
||||
func TestWriterCreation(t *testing.T) {
|
||||
tcpServer := tcp.Server{}
|
||||
dest, err := tcpServer.Start()
|
||||
if err != nil {
|
||||
t.Fatal("failed to start tcp server: ", err)
|
||||
}
|
||||
defer tcpServer.Close()
|
||||
|
||||
conn, err := net.Dial("tcp", dest.NetAddr())
|
||||
if err != nil {
|
||||
t.Fatal("failed to dial a TCP connection: ", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
{
|
||||
writer := NewWriter(conn)
|
||||
if _, ok := writer.(*BufferToBytesWriter); !ok {
|
||||
t.Fatal("writer is not a BufferToBytesWriter")
|
||||
}
|
||||
|
||||
writer2 := NewWriter(writer.(io.Writer))
|
||||
if writer2 != writer {
|
||||
t.Fatal("writer is not reused")
|
||||
}
|
||||
}
|
||||
|
||||
tlsConn := tls.Client(conn, &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
})
|
||||
defer tlsConn.Close()
|
||||
|
||||
{
|
||||
writer := NewWriter(tlsConn)
|
||||
if _, ok := writer.(*SequentialWriter); !ok {
|
||||
t.Fatal("writer is not a SequentialWriter")
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import "net"
|
||||
var DialTCP = net.DialTCP
|
||||
var DialUDP = net.DialUDP
|
||||
var DialUnix = net.DialUnix
|
||||
var Dial = net.Dial
|
||||
|
||||
var Listen = net.Listen
|
||||
var ListenTCP = net.ListenTCP
|
||||
|
Loading…
Reference in New Issue
Block a user