From 7ef249f8dbbdf44400e3e53cbf671d8769a98e0d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 17 Sep 2020 13:11:40 +0300 Subject: [PATCH] [#149] sdk/netmap: Add net address getter to Node Signed-off-by: Leonard Lyubich --- pkg/netmap/node_info.go | 6 ++++++ pkg/netmap/node_info_test.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 pkg/netmap/node_info_test.go diff --git a/pkg/netmap/node_info.go b/pkg/netmap/node_info.go index 4634c8ef..03a04b3b 100644 --- a/pkg/netmap/node_info.go +++ b/pkg/netmap/node_info.go @@ -38,6 +38,12 @@ func (n Node) Hash() uint64 { return n.ID } +// NetworkAddress returns network address +// of the node in a string format. +func (n Node) NetworkAddress() string { + return n.InfoV2.GetAddress() +} + // NodesFromV2 converts slice of v2 netmap.NodeInfo to a generic node slice. func NodesFromV2(infos []netmap.NodeInfo) Nodes { nodes := make(Nodes, len(infos)) diff --git a/pkg/netmap/node_info_test.go b/pkg/netmap/node_info_test.go new file mode 100644 index 00000000..0da6ad27 --- /dev/null +++ b/pkg/netmap/node_info_test.go @@ -0,0 +1,21 @@ +package netmap + +import ( + "testing" + + "github.com/nspcc-dev/neofs-api-go/v2/netmap" + "github.com/stretchr/testify/require" +) + +func TestNode_NetworkAddress(t *testing.T) { + addr := "127.0.0.1:8080" + + nV2 := new(netmap.NodeInfo) + nV2.SetAddress(addr) + + n := Node{ + InfoV2: nV2, + } + + require.Equal(t, addr, n.NetworkAddress()) +}