[#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 <carpawell@nspcc.ru>
This commit is contained in:
parent
2307c8f8f7
commit
c978fa0e21
2 changed files with 21 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue