diff --git a/pkg/object/splitid.go b/pkg/object/splitid.go index 8e9eaa2a..e495e8dd 100644 --- a/pkg/object/splitid.go +++ b/pkg/object/splitid.go @@ -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 diff --git a/pkg/object/splitid_test.go b/pkg/object/splitid_test.go index 04b40f7b..7371ed3e 100644 --- a/pkg/object/splitid_test.go +++ b/pkg/object/splitid_test.go @@ -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)) + }) +}