trpc.group/trpc-go/trpc-go@v1.0.3/internal/addrutil/addrutil_test.go (about)

     1  package addrutil_test
     2  
     3  import (
     4  	"net"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  	"trpc.group/trpc-go/trpc-go/internal/addrutil"
     9  )
    10  
    11  func TestAddrToKey(t *testing.T) {
    12  	laddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:10000")
    13  	require.Nil(t, err)
    14  	raddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:10001")
    15  	require.Nil(t, err)
    16  	key := addrutil.AddrToKey(laddr, raddr)
    17  	require.Equal(t, key, laddr.Network()+"_"+laddr.String()+"_"+raddr.String())
    18  }