2016-06-14 20:54:08 +00:00
|
|
|
package internet_test
|
2016-01-21 12:18:37 +00:00
|
|
|
|
|
|
|
import (
|
2017-04-08 22:54:07 +00:00
|
|
|
"context"
|
2016-01-21 12:18:37 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-01-08 22:27:02 +00:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
|
|
|
"v2ray.com/core/common"
|
2017-01-13 23:27:45 +00:00
|
|
|
"v2ray.com/core/common/net"
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/testing/servers/tcp"
|
|
|
|
. "v2ray.com/core/transport/internet"
|
2016-01-21 12:18:37 +00:00
|
|
|
)
|
|
|
|
|
2016-06-03 22:38:22 +00:00
|
|
|
func TestDialWithLocalAddr(t *testing.T) {
|
2016-08-15 20:12:11 +00:00
|
|
|
server := &tcp.Server{}
|
2016-06-03 22:38:22 +00:00
|
|
|
dest, err := server.Start()
|
2019-01-08 22:27:02 +00:00
|
|
|
common.Must(err)
|
2016-06-03 22:38:22 +00:00
|
|
|
defer server.Close()
|
|
|
|
|
2018-11-21 13:54:40 +00:00
|
|
|
conn, err := DialSystem(context.Background(), net.TCPDestination(net.LocalHostIP, dest.Port), nil)
|
2019-01-08 22:27:02 +00:00
|
|
|
common.Must(err)
|
|
|
|
if r := cmp.Diff(conn.RemoteAddr().String(), "127.0.0.1:"+dest.Port.String()); r != "" {
|
|
|
|
t.Error(r)
|
|
|
|
}
|
2016-01-21 12:18:37 +00:00
|
|
|
conn.Close()
|
|
|
|
}
|