forked from TrueCloudLab/frostfs-api-go
[#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 <carpawell@nspcc.ru>
This commit is contained in:
parent
fb77bd3511
commit
934cf8ecc8
2 changed files with 21 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue