github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/transport/internet/dialer_test.go (about) 1 package internet_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 9 "github.com/v2fly/v2ray-core/v5/common" 10 "github.com/v2fly/v2ray-core/v5/common/net" 11 "github.com/v2fly/v2ray-core/v5/testing/servers/tcp" 12 . "github.com/v2fly/v2ray-core/v5/transport/internet" 13 ) 14 15 func TestDialWithLocalAddr(t *testing.T) { 16 server := &tcp.Server{} 17 dest, err := server.Start() 18 common.Must(err) 19 defer server.Close() 20 21 conn, err := DialSystem(context.Background(), net.TCPDestination(net.LocalHostIP, dest.Port), nil) 22 common.Must(err) 23 if r := cmp.Diff(conn.RemoteAddr().String(), "127.0.0.1:"+dest.Port.String()); r != "" { 24 t.Error(r) 25 } 26 conn.Close() 27 }