forked from TrueCloudLab/frostfs-api-go
[#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:
parent
2fb67d99d3
commit
bbd651767e
2 changed files with 23 additions and 0 deletions
|
@ -18,7 +18,13 @@ func NewSplitID() *SplitID {
|
||||||
|
|
||||||
// NewSplitIDFromV2 returns parsed UUID from bytes.
|
// NewSplitIDFromV2 returns parsed UUID from bytes.
|
||||||
// If v is invalid UUIDv4 byte sequence, then function returns nil.
|
// If v is invalid UUIDv4 byte sequence, then function returns nil.
|
||||||
|
//
|
||||||
|
// Nil converts to nil.
|
||||||
func NewSplitIDFromV2(v []byte) *SplitID {
|
func NewSplitIDFromV2(v []byte) *SplitID {
|
||||||
|
if v == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
|
|
||||||
err := id.UnmarshalBinary(v)
|
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.
|
// ToV2 converts SplitID to a representation of SplitID in neofs-api v2.
|
||||||
|
//
|
||||||
|
// Nil SplitID converts to nil.
|
||||||
func (id *SplitID) ToV2() []byte {
|
func (id *SplitID) ToV2() []byte {
|
||||||
if id == nil {
|
if id == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -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))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue