[#302] pkg/object: Convert nil SplitID to nil message

Document that `SplitID.ToV2` method return `nil`
when called on `nil`. Document that `NewSplitIDFromV2`
function return `nil` when called on `nil`. Write
corresponding unit tests.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-09 16:18:56 +03:00 committed by Alex Vanin
parent 2fb67d99d3
commit bbd651767e
2 changed files with 23 additions and 0 deletions

View file

@ -18,7 +18,13 @@ func NewSplitID() *SplitID {
// NewSplitIDFromV2 returns parsed UUID from bytes.
// If v is invalid UUIDv4 byte sequence, then function returns nil.
//
// Nil converts to nil.
func NewSplitIDFromV2(v []byte) *SplitID {
if v == nil {
return nil
}
id := uuid.New()
err := id.UnmarshalBinary(v)
@ -58,6 +64,8 @@ func (id *SplitID) SetUUID(v uuid.UUID) {
}
// ToV2 converts SplitID to a representation of SplitID in neofs-api v2.
//
// Nil SplitID converts to nil.
func (id *SplitID) ToV2() []byte {
if id == nil {
return nil

View file

@ -46,3 +46,18 @@ func TestSplitID(t *testing.T) {
})
}
func TestSplitID_ToV2(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var x *object.SplitID
require.Nil(t, x.ToV2())
})
}
func TestNewIDFromV2(t *testing.T) {
t.Run("from nil", func(t *testing.T) {
var x []byte
require.Nil(t, object.NewSplitIDFromV2(x))
})
}