mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
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"
|
||||
|
||||
. "github.com/xtls/xray-core/v1/common/buf"
|
||||
"github.com/xtls/xray-core/v1/common/net"
|
||||
"github.com/xtls/xray-core/v1/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")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue