From 4e40f195bcd0acd4a406f4ba04ed65b43f8911ea Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 19:06:43 +0300 Subject: [PATCH] [#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 --- pkg/object/range.go | 4 ++++ pkg/object/range_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/object/range.go b/pkg/object/range.go index 901bd3f2..d87672e7 100644 --- a/pkg/object/range.go +++ b/pkg/object/range.go @@ -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) } diff --git a/pkg/object/range_test.go b/pkg/object/range_test.go index 4cce11d1..099b7440 100644 --- a/pkg/object/range_test.go +++ b/pkg/object/range_test.go @@ -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()) + }) +}