From c978fa0e215b712aeeb73cd4322bf4ca97c7bf64 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 18:44:47 +0300 Subject: [PATCH] [#302] pkg/object: Convert nil `Address` to nil message Document that `Address.ToV2` method return `nil` when called on `nil`. Document that `NewAddressFromV2` function return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy --- pkg/object/address.go | 4 ++++ pkg/object/address_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/object/address.go b/pkg/object/address.go index a241e63..54d550f 100644 --- a/pkg/object/address.go +++ b/pkg/object/address.go @@ -19,6 +19,8 @@ const ( ) // NewAddressFromV2 converts v2 Address message to Address. +// +// Nil refs.Address converts to nil. func NewAddressFromV2(aV2 *refs.Address) *Address { return (*Address)(aV2) } @@ -31,6 +33,8 @@ func NewAddress() *Address { } // ToV2 converts Address to v2 Address message. +// +// Nil Address converts to nil. func (a *Address) ToV2() *refs.Address { return (*refs.Address)(a) } diff --git a/pkg/object/address_test.go b/pkg/object/address_test.go index 652f44b..f3b8b35 100644 --- a/pkg/object/address_test.go +++ b/pkg/object/address_test.go @@ -5,6 +5,7 @@ import ( "testing" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" + "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/stretchr/testify/require" ) @@ -84,3 +85,19 @@ func TestAddressEncoding(t *testing.T) { require.Equal(t, a, a2) }) } + +func TestNewAddressFromV2(t *testing.T) { + t.Run("from nil", func(t *testing.T) { + var x *refs.Address + + require.Nil(t, NewAddressFromV2(x)) + }) +} + +func TestAddress_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *Address + + require.Nil(t, x.ToV2()) + }) +}