[#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>
remotes/KirillovDenis/feature/refactor-sig-rpc
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
// NewTombstoneFromV2 wraps v2 Tombstone message to Tombstone.
//
// Nil tombstone.Tombstone converts to nil.
func NewTombstoneFromV2(tV2 *tombstone.Tombstone) *Tombstone {
return (*Tombstone)(tV2)
}

View File

@ -5,6 +5,7 @@ import (
"crypto/sha256"
"testing"
"github.com/nspcc-dev/neofs-api-go/v2/tombstone"
"github.com/stretchr/testify/require"
)
@ -63,3 +64,11 @@ func TestTombstoneEncoding(t *testing.T) {
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))
})
}