[#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 <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 19:27:53 +03:00 committed by Alex Vanin
parent d443904e43
commit 5cbdef1e46
2 changed files with 23 additions and 0 deletions

View file

@ -6,6 +6,9 @@ import (
type SplitInfo object.SplitInfo type SplitInfo object.SplitInfo
// NewSplitInfoFromV2 wraps v2 SplitInfo message to SplitInfo.
//
// Nil object.SplitInfo converts to nil.
func NewSplitInfoFromV2(v2 *object.SplitInfo) *SplitInfo { func NewSplitInfoFromV2(v2 *object.SplitInfo) *SplitInfo {
return (*SplitInfo)(v2) return (*SplitInfo)(v2)
} }
@ -14,6 +17,9 @@ func NewSplitInfo() *SplitInfo {
return NewSplitInfoFromV2(new(object.SplitInfo)) return NewSplitInfoFromV2(new(object.SplitInfo))
} }
// ToV2 converts SplitInfo to v2 SplitInfo message.
//
// Nil SplitInfo converts to nil.
func (s *SplitInfo) ToV2() *object.SplitInfo { func (s *SplitInfo) ToV2() *object.SplitInfo {
return (*object.SplitInfo)(s) return (*object.SplitInfo)(s)
} }

View file

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
objv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -51,3 +52,19 @@ func generateID() *object.ID {
return 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())
})
}