[#302] pkg/object: Convert nil Tombstone to nil message

Document that `NewTombstoneFromV2` 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:37:35 +03:00 committed by Alex Vanin
parent dde721ea9f
commit 753402c336
3 changed files with 12 additions and 0 deletions

View file

@ -45,3 +45,4 @@ func TestSplitID(t *testing.T) {
}) })
}) })
} }

View file

@ -9,6 +9,8 @@ import (
type Tombstone tombstone.Tombstone type Tombstone tombstone.Tombstone
// NewTombstoneFromV2 wraps v2 Tombstone message to Tombstone. // NewTombstoneFromV2 wraps v2 Tombstone message to Tombstone.
//
// Nil tombstone.Tombstone converts to nil.
func NewTombstoneFromV2(tV2 *tombstone.Tombstone) *Tombstone { func NewTombstoneFromV2(tV2 *tombstone.Tombstone) *Tombstone {
return (*Tombstone)(tV2) return (*Tombstone)(tV2)
} }

View file

@ -5,6 +5,7 @@ import (
"crypto/sha256" "crypto/sha256"
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/v2/tombstone"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -63,3 +64,11 @@ func TestTombstoneEncoding(t *testing.T) {
require.Equal(t, ts, ts2) require.Equal(t, ts, ts2)
}) })
} }
func TestNewTombstoneFromV2(t *testing.T) {
t.Run("from nil", func(t *testing.T) {
var x *tombstone.Tombstone
require.Nil(t, NewTombstoneFromV2(x))
})
}