From 934cf8ecc88ef3763bfead42d49243159f743ac1 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 20:39:26 +0300 Subject: [PATCH] [#302] pkg/storagegroup: Convert nil `StorageGroup` to nil message Document that `StorageGroup.ToV2` method return `nil` when called on `nil`. Document that `NewFromV2` function return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy --- pkg/storagegroup/storagegroup.go | 4 ++++ pkg/storagegroup/storagegroup_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/storagegroup/storagegroup.go b/pkg/storagegroup/storagegroup.go index 0ae52abc..c1994c3a 100644 --- a/pkg/storagegroup/storagegroup.go +++ b/pkg/storagegroup/storagegroup.go @@ -11,6 +11,8 @@ import ( type StorageGroup storagegroup.StorageGroup // NewFromV2 wraps v2 StorageGroup message to StorageGroup. +// +// Nil storagegroup.StorageGroup converts to nil. func NewFromV2(aV2 *storagegroup.StorageGroup) *StorageGroup { return (*StorageGroup)(aV2) } @@ -110,6 +112,8 @@ func (sg *StorageGroup) SetMembers(members []*object.ID) { } // ToV2 converts StorageGroup to v2 StorageGroup message. +// +// Nil StorageGroup converts to nil. func (sg *StorageGroup) ToV2() *storagegroup.StorageGroup { return (*storagegroup.StorageGroup)(sg) } diff --git a/pkg/storagegroup/storagegroup_test.go b/pkg/storagegroup/storagegroup_test.go index 51184312..b89f5440 100644 --- a/pkg/storagegroup/storagegroup_test.go +++ b/pkg/storagegroup/storagegroup_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/storagegroup" storagegrouptest "github.com/nspcc-dev/neofs-api-go/pkg/storagegroup/test" refstest "github.com/nspcc-dev/neofs-api-go/pkg/test" + storagegroupV2 "github.com/nspcc-dev/neofs-api-go/v2/storagegroup" "github.com/stretchr/testify/require" ) @@ -54,3 +55,19 @@ func TestStorageGroupEncoding(t *testing.T) { require.Equal(t, sg, sg2) }) } + +func TestNewFromV2(t *testing.T) { + t.Run("from nil", func(t *testing.T) { + var x *storagegroupV2.StorageGroup + + require.Nil(t, storagegroup.NewFromV2(x)) + }) +} + +func TestStorageGroup_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *storagegroup.StorageGroup + + require.Nil(t, x.ToV2()) + }) +}