github.com/EagleQL/Xray-core@v1.4.3/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/xtls/xray-core/common"
    10  	"github.com/xtls/xray-core/common/net"
    11  	"github.com/xtls/xray-core/testing/servers/tcp"
    12  	. "github.com/xtls/xray-core/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  }