github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/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/xmplusdev/xmcore/common"
    12  	"github.com/xmplusdev/xmcore/testing/servers/tcp"
    13  	"github.com/xmplusdev/xmcore/transport/internet"
    14  	. "github.com/xmplusdev/xmcore/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  }