1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 03:37:37 -05:00
v2fly/transport/internet/tcp/sockopt_linux_test.go

34 lines
741 B
Go
Raw Normal View History

2017-04-18 06:02:43 -04:00
// +build linux
package tcp_test
import (
"context"
2017-04-19 05:52:17 -04:00
"strings"
2017-04-18 06:02:43 -04:00
"testing"
2018-11-22 11:30:06 -05:00
"v2ray.com/core/common"
2017-04-18 06:02:43 -04:00
"v2ray.com/core/testing/servers/tcp"
2018-11-22 11:19:24 -05:00
"v2ray.com/core/transport/internet"
2017-04-18 06:12:17 -04:00
. "v2ray.com/core/transport/internet/tcp"
2017-10-24 11:36:42 -04:00
. "v2ray.com/ext/assert"
2017-04-18 06:02:43 -04:00
)
func TestGetOriginalDestination(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-04-18 06:02:43 -04:00
2017-04-18 06:12:17 -04:00
tcpServer := tcp.Server{}
2017-04-18 06:02:43 -04:00
dest, err := tcpServer.Start()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-04-18 06:02:43 -04:00
defer tcpServer.Close()
2018-11-22 11:30:06 -05:00
config, err := internet.ToMemoryStreamConfig(nil)
common.Must(err)
conn, err := Dial(context.Background(), dest, config)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
2017-04-18 06:12:17 -04:00
defer conn.Close()
2017-04-18 06:02:43 -04:00
2017-04-19 05:52:17 -04:00
originalDest, err := GetOriginalDestination(conn)
2017-10-24 11:36:42 -04:00
assert(dest == originalDest || strings.Contains(err.Error(), "failed to call getsockopt"), IsTrue)
2017-04-18 06:02:43 -04:00
}