[#607] network: Remove Address methods used only for testing

Remove `Encapsulate`, `Decapsulate` and `IPAddrString` methods of `Address`
since they are used in unit tests only.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-16 14:14:23 +03:00 committed by Leonard Lyubich
parent 47fe8911a3
commit dd67e2b690
2 changed files with 0 additions and 108 deletions

View file

@ -27,22 +27,6 @@ type LocalAddressSource interface {
LocalAddress() *Address
}
// Encapsulate wraps this Address around another. For example:
//
// /ip4/1.2.3.4 encapsulate /tcp/80 = /ip4/1.2.3.4/tcp/80
//
func (a *Address) Encapsulate(addr *Address) {
a.ma = a.ma.Encapsulate(addr.ma)
}
// Decapsulate removes an Address wrapping. For example:
//
// /ip4/1.2.3.4/tcp/80 decapsulate /ip4/1.2.3.4 = /tcp/80
//
func (a *Address) Decapsulate(addr *Address) {
a.ma = a.ma.Decapsulate(addr.ma)
}
// String returns multiaddr string
func (a Address) String() string {
return a.ma.String()
@ -53,16 +37,6 @@ func (a Address) Equal(addr Address) bool {
return a.ma.Equal(addr.ma)
}
// IPAddrString returns network endpoint address in string format.
func (a Address) IPAddrString() (string, error) {
ip, err := manet.ToNetAddr(a.ma)
if err != nil {
return "", fmt.Errorf("could not get net addr: %w", err)
}
return ip.String(), nil
}
// HostAddr returns host address in string format.
//
// Panics if host address cannot be fetched from Address.

View file

@ -1,34 +1,12 @@
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)
netAddr, err := addr.IPAddrString()
require.NoError(t, err)
require.Equal(t, ip+":"+port, netAddr)
}
func TestAddressFromString(t *testing.T) {
t.Run("valid addresses", func(t *testing.T) {
testcases := []struct {
@ -80,66 +58,6 @@ func TestAddress_HostAddrString(t *testing.T) {
})
}
func TestAddress_Encapsulate(t *testing.T) {
ma1, ma2 := "/dns4/neofs.bigcorp.com/tcp/8080", "/tls"
testcases := []struct {
ma1 multiaddr.Multiaddr
ma2 multiaddr.Multiaddr
want string
}{
{
buildMultiaddr(ma1, t),
buildMultiaddr(ma2, t),
ma1 + ma2,
},
{
buildMultiaddr(ma2, t),
buildMultiaddr(ma1, t),
ma2 + ma1,
},
}
for _, testcase := range testcases {
addr1 := &Address{testcase.ma1}
addr2 := &Address{testcase.ma2}
addr1.Encapsulate(addr2)
require.Equal(t, addr1.String(), testcase.want)
}
}
func TestAddress_Decapsulate(t *testing.T) {
ma1, ma2 := "/dns4/neofs.bigcorp.com/tcp/8080", "/tls"
testcases := []struct {
ma1 multiaddr.Multiaddr
ma2 multiaddr.Multiaddr
want string
}{
{
buildMultiaddr(ma1+ma2, t),
buildMultiaddr(ma2, t),
ma1,
},
{
buildMultiaddr(ma2+ma1, t),
buildMultiaddr(ma1, t),
ma2,
},
}
for _, testcase := range testcases {
addr1 := &Address{testcase.ma1}
addr2 := &Address{testcase.ma2}
addr1.Decapsulate(addr2)
require.Equal(t, addr1.String(), testcase.want)
}
}
func buildMultiaddr(s string, t *testing.T) multiaddr.Multiaddr {
ma, err := multiaddr.NewMultiaddr(s)
require.NoError(t, err)