github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/tcp/sockopt_linux_test.go (about)

     1  // +build linux
     2  
     3  package tcp_test
     4  
     5  import (
     6  	"context"
     7  	"strings"
     8  	"testing"
     9  
    10  	"v2ray.com/core/common"
    11  	"v2ray.com/core/testing/servers/tcp"
    12  	"v2ray.com/core/transport/internet"
    13  	. "v2ray.com/core/transport/internet/tcp"
    14  )
    15  
    16  func TestGetOriginalDestination(t *testing.T) {
    17  	tcpServer := tcp.Server{}
    18  	dest, err := tcpServer.Start()
    19  	common.Must(err)
    20  	defer tcpServer.Close()
    21  
    22  	config, err := internet.ToMemoryStreamConfig(nil)
    23  	common.Must(err)
    24  	conn, err := Dial(context.Background(), dest, config)
    25  	common.Must(err)
    26  	defer conn.Close()
    27  
    28  	originalDest, err := GetOriginalDestination(conn)
    29  	if !(dest == originalDest || strings.Contains(err.Error(), "failed to call getsockopt")) {
    30  		t.Error("unexpected state")
    31  	}
    32  }