diff --git a/pkg/netmap/node_info.go b/pkg/netmap/node_info.go index 17aa9f4..935f9d2 100644 --- a/pkg/netmap/node_info.go +++ b/pkg/netmap/node_info.go @@ -193,11 +193,15 @@ func NewNodeAttribute() *NodeAttribute { } // NodeAttributeFromV2 converts v2 node Attribute to NodeAttribute. +// +// Nil netmap.Attribute converts to nil. func NewNodeAttributeFromV2(a *netmap.Attribute) *NodeAttribute { return (*NodeAttribute)(a) } // ToV2 converts NodeAttribute to v2 node Attribute. +// +// Nil NodeAttribute converts to nil. func (a *NodeAttribute) ToV2() *netmap.Attribute { return (*netmap.Attribute)(a) } @@ -276,11 +280,15 @@ func NewNodeInfo() *NodeInfo { } // NewNodeInfoFromV2 converts v2 NodeInfo to NodeInfo. +// +// Nil netmap.NodeInfo converts to nil. func NewNodeInfoFromV2(i *netmap.NodeInfo) *NodeInfo { return (*NodeInfo)(i) } // ToV2 converts NodeInfo to v2 NodeInfo. +// +// Nil NodeInfo converts to nil. func (i *NodeInfo) ToV2() *netmap.NodeInfo { return (*netmap.NodeInfo)(i) } diff --git a/pkg/netmap/node_info_test.go b/pkg/netmap/node_info_test.go index 9b50a9b..ea80656 100644 --- a/pkg/netmap/node_info_test.go +++ b/pkg/netmap/node_info_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/nspcc-dev/neofs-api-go/v2/netmap" + testv2 "github.com/nspcc-dev/neofs-api-go/v2/netmap/test" "github.com/stretchr/testify/require" ) @@ -31,14 +32,27 @@ func TestNodeStateFromV2(t *testing.T) { } func TestNodeAttributeFromV2(t *testing.T) { - aV2 := new(netmap.Attribute) - aV2.SetKey("key") - aV2.SetValue("value") - aV2.SetParents([]string{"par1", "par2"}) + t.Run("from nil", func(t *testing.T) { + var x *netmap.Attribute - a := NewNodeAttributeFromV2(aV2) + require.Nil(t, NewNodeAttributeFromV2(x)) + }) - require.Equal(t, aV2, a.ToV2()) + t.Run("from non-nil", func(t *testing.T) { + aV2 := testv2.GenerateAttribute(false) + + a := NewNodeAttributeFromV2(aV2) + + require.Equal(t, aV2, a.ToV2()) + }) +} + +func TestNodeAttribute_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *NodeAttribute + + require.Nil(t, x.ToV2()) + }) } func TestNodeAttribute_Key(t *testing.T) { @@ -78,18 +92,27 @@ func testNodeAttribute() *NodeAttribute { } func TestNodeInfoFromV2(t *testing.T) { - iV2 := new(netmap.NodeInfo) - iV2.SetPublicKey([]byte{1, 2, 3}) - iV2.SetAddress("456") - iV2.SetState(netmap.Online) - iV2.SetAttributes([]*netmap.Attribute{ - testNodeAttribute().ToV2(), - testNodeAttribute().ToV2(), + t.Run("from nil", func(t *testing.T) { + var x *netmap.NodeInfo + + require.Nil(t, NewNodeInfoFromV2(x)) }) - i := NewNodeInfoFromV2(iV2) + t.Run("from non-nil", func(t *testing.T) { + iV2 := testv2.GenerateNodeInfo(false) - require.Equal(t, iV2, i.ToV2()) + i := NewNodeInfoFromV2(iV2) + + require.Equal(t, iV2, i.ToV2()) + }) +} + +func TestNodeInfo_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *NodeInfo + + require.Nil(t, x.ToV2()) + }) } func TestNodeInfo_PublicKey(t *testing.T) {