github.com/xraypb/Xray-core@v1.8.1/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  	"github.com/xraypb/Xray-core/common"
     9  	"github.com/xraypb/Xray-core/common/net"
    10  	"github.com/xraypb/Xray-core/testing/servers/tcp"
    11  	. "github.com/xraypb/Xray-core/transport/internet"
    12  )
    13  
    14  func TestDialWithLocalAddr(t *testing.T) {
    15  	server := &tcp.Server{}
    16  	dest, err := server.Start()
    17  	common.Must(err)
    18  	defer server.Close()
    19  
    20  	conn, err := DialSystem(context.Background(), net.TCPDestination(net.LocalHostIP, dest.Port), nil)
    21  	common.Must(err)
    22  	if r := cmp.Diff(conn.RemoteAddr().String(), "127.0.0.1:"+dest.Port.String()); r != "" {
    23  		t.Error(r)
    24  	}
    25  	conn.Close()
    26  }