From 5cbdef1e467db1750f044df73013362bdff9b831 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 19:27:53 +0300 Subject: [PATCH] [#302] pkg/object: Convert nil `SplitInfo` to nil message Document that `SplitInfo.ToV2` method return `nil` when called on `nil`. Document that `NewSplitInfoFromV2` function return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy --- pkg/object/splitinfo.go | 6 ++++++ pkg/object/splitinfo_test.go | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pkg/object/splitinfo.go b/pkg/object/splitinfo.go index 600b87b5..cbe71620 100644 --- a/pkg/object/splitinfo.go +++ b/pkg/object/splitinfo.go @@ -6,6 +6,9 @@ import ( type SplitInfo object.SplitInfo +// NewSplitInfoFromV2 wraps v2 SplitInfo message to SplitInfo. +// +// Nil object.SplitInfo converts to nil. func NewSplitInfoFromV2(v2 *object.SplitInfo) *SplitInfo { return (*SplitInfo)(v2) } @@ -14,6 +17,9 @@ func NewSplitInfo() *SplitInfo { return NewSplitInfoFromV2(new(object.SplitInfo)) } +// ToV2 converts SplitInfo to v2 SplitInfo message. +// +// Nil SplitInfo converts to nil. func (s *SplitInfo) ToV2() *object.SplitInfo { return (*object.SplitInfo)(s) } diff --git a/pkg/object/splitinfo_test.go b/pkg/object/splitinfo_test.go index 8f07313c..62387101 100644 --- a/pkg/object/splitinfo_test.go +++ b/pkg/object/splitinfo_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/nspcc-dev/neofs-api-go/pkg/object" + objv2 "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/stretchr/testify/require" ) @@ -51,3 +52,19 @@ func generateID() *object.ID { return id } + +func TestNewSplitInfoFromV2(t *testing.T) { + t.Run("from nil", func(t *testing.T) { + var x *objv2.SplitInfo + + require.Nil(t, object.NewSplitInfoFromV2(x)) + }) +} + +func TestSplitInfo_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *object.SplitInfo + + require.Nil(t, x.ToV2()) + }) +}