github.com/moqsien/xraycore@v1.8.5/transport/internet/tcp/sockopt_linux_test.go (about)

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