[#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
|
type Range object.Range
|
||||||
|
|
||||||
// NewRangeFromV2 wraps v2 Range message to Range.
|
// NewRangeFromV2 wraps v2 Range message to Range.
|
||||||
|
//
|
||||||
|
// Nil object.Range converts to nil.
|
||||||
func NewRangeFromV2(rV2 *object.Range) *Range {
|
func NewRangeFromV2(rV2 *object.Range) *Range {
|
||||||
return (*Range)(rV2)
|
return (*Range)(rV2)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +20,8 @@ func NewRange() *Range {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToV2 converts Range to v2 Range message.
|
// ToV2 converts Range to v2 Range message.
|
||||||
|
//
|
||||||
|
// Nil Range converts to nil.
|
||||||
func (r *Range) ToV2() *object.Range {
|
func (r *Range) ToV2() *object.Range {
|
||||||
return (*object.Range)(r)
|
return (*object.Range)(r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package object
|
package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -23,3 +24,19 @@ func TestRange_SetLength(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, ln, r.GetLength())
|
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