2020-09-21 09:32:19 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAddress_NetAddr(t *testing.T) {
|
|
|
|
ip := "127.0.0.1"
|
|
|
|
port := "8080"
|
|
|
|
|
|
|
|
ma, err := multiaddr.NewMultiaddr(strings.Join([]string{
|
|
|
|
"/ip4",
|
|
|
|
ip,
|
|
|
|
"tcp",
|
|
|
|
port,
|
|
|
|
}, "/"))
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
addr, err := AddressFromString(ma.String())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-24 08:27:14 +00:00
|
|
|
netAddr, err := addr.IPAddrString()
|
2020-09-24 07:37:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, ip+":"+port, netAddr)
|
2020-09-21 09:32:19 +00:00
|
|
|
}
|