From 753402c336159ce559ef9ab4e1655337e109ee11 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 19:37:35 +0300 Subject: [PATCH] [#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 --- pkg/object/splitid_test.go | 1 + pkg/object/tombstone.go | 2 ++ pkg/object/tombstone_test.go | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/pkg/object/splitid_test.go b/pkg/object/splitid_test.go index 8adcc86..04b40f7 100644 --- a/pkg/object/splitid_test.go +++ b/pkg/object/splitid_test.go @@ -45,3 +45,4 @@ func TestSplitID(t *testing.T) { }) }) } + diff --git a/pkg/object/tombstone.go b/pkg/object/tombstone.go index 469e684..add7f5d 100644 --- a/pkg/object/tombstone.go +++ b/pkg/object/tombstone.go @@ -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) } diff --git a/pkg/object/tombstone_test.go b/pkg/object/tombstone_test.go index 21103ba..f9a0650 100644 --- a/pkg/object/tombstone_test.go +++ b/pkg/object/tombstone_test.go @@ -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)) + }) +}