[#302] pkg/object: Convert nil Range
to nil message
Document that `Range.ToV2` method return `nil` when called on `nil`. Document that `NewRangeFromV2` 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
6c12b4dfb6
commit
4e40f195bc
2 changed files with 21 additions and 0 deletions
|
@ -8,6 +8,8 @@ import (
|
|||
type Range object.Range
|
||||
|
||||
// NewRangeFromV2 wraps v2 Range message to Range.
|
||||
//
|
||||
// Nil object.Range converts to nil.
|
||||
func NewRangeFromV2(rV2 *object.Range) *Range {
|
||||
return (*Range)(rV2)
|
||||
}
|
||||
|
@ -18,6 +20,8 @@ func NewRange() *Range {
|
|||
}
|
||||
|
||||
// ToV2 converts Range to v2 Range message.
|
||||
//
|
||||
// Nil Range converts to nil.
|
||||
func (r *Range) ToV2() *object.Range {
|
||||
return (*object.Range)(r)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package object
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -23,3 +24,19 @@ func TestRange_SetLength(t *testing.T) {
|
|||
|
||||
require.Equal(t, ln, r.GetLength())
|
||||
}
|
||||
|
||||
func TestNewRangeFromV2(t *testing.T) {
|
||||
t.Run("from nil", func(t *testing.T) {
|
||||
var x *object.Range
|
||||
|
||||
require.Nil(t, NewRangeFromV2(x))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRange_ToV2(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
var x *Range
|
||||
|
||||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue