github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/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/xmplusdev/xmcore/common" 9 "github.com/xmplusdev/xmcore/common/net" 10 "github.com/xmplusdev/xmcore/testing/servers/tcp" 11 . "github.com/xmplusdev/xmcore/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 }