From d443904e43e121257264a5cdfad4c67c4fb41119 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 19:09:39 +0300 Subject: [PATCH] [#302] pkg/object: Document default values set in `NewRange` Document field values of instance constructed via `NewRange`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/object/range.go | 4 ++++ pkg/object/range_test.go | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/object/range.go b/pkg/object/range.go index d87672e..4979aee 100644 --- a/pkg/object/range.go +++ b/pkg/object/range.go @@ -15,6 +15,10 @@ func NewRangeFromV2(rV2 *object.Range) *Range { } // NewRange creates and initializes blank Range. +// +// Defaults: +// - offset: 0; +// - length: 0. func NewRange() *Range { return NewRangeFromV2(new(object.Range)) } diff --git a/pkg/object/range_test.go b/pkg/object/range_test.go index 099b744..e14d360 100644 --- a/pkg/object/range_test.go +++ b/pkg/object/range_test.go @@ -1,9 +1,9 @@ package object import ( - "github.com/nspcc-dev/neofs-api-go/v2/object" "testing" + "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/stretchr/testify/require" ) @@ -40,3 +40,19 @@ func TestRange_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNewRange(t *testing.T) { + t.Run("default values", func(t *testing.T) { + r := NewRange() + + // check initial values + require.Zero(t, r.GetLength()) + require.Zero(t, r.GetOffset()) + + // convert to v2 message + rV2 := r.ToV2() + + require.Zero(t, rV2.GetLength()) + require.Zero(t, rV2.GetOffset()) + }) +}