1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-07 10:47:48 -05:00
v2fly/transport/internet/dialer_test.go

39 lines
993 B
Go
Raw Normal View History

2016-06-14 16:54:08 -04:00
package internet_test
2016-01-21 07:18:37 -05:00
import (
"testing"
2016-08-20 14:55:45 -04:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
"v2ray.com/core/testing/servers/tcp"
. "v2ray.com/core/transport/internet"
2016-01-21 07:18:37 -05:00
)
func TestDialDomain(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-01-21 07:18:37 -05:00
2016-08-15 16:12:11 -04:00
server := &tcp.Server{}
2016-01-21 07:27:08 -05:00
dest, err := server.Start()
2016-01-21 07:18:37 -05:00
assert.Error(err).IsNil()
2016-01-21 16:45:44 -05:00
defer server.Close()
2016-01-21 07:27:08 -05:00
2016-06-14 16:54:08 -04:00
conn, err := DialToDest(nil, v2net.TCPDestination(v2net.DomainAddress("local.v2ray.com"), dest.Port()))
2016-06-03 18:38:22 -04:00
assert.Error(err).IsNil()
assert.String(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port().String())
conn.Close()
}
func TestDialWithLocalAddr(t *testing.T) {
assert := assert.On(t)
2016-08-15 16:12:11 -04:00
server := &tcp.Server{}
2016-06-03 18:38:22 -04:00
dest, err := server.Start()
assert.Error(err).IsNil()
defer server.Close()
2016-06-14 16:54:08 -04:00
conn, err := DialToDest(v2net.LocalHostIP, v2net.TCPDestination(v2net.LocalHostIP, dest.Port()))
2016-01-21 07:27:08 -05:00
assert.Error(err).IsNil()
2016-05-24 15:55:46 -04:00
assert.String(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port().String())
2016-01-21 07:18:37 -05:00
conn.Close()
}