diff --git a/pkg/object/tombstone.go b/pkg/object/tombstone.go index add7f5d..1d7e522 100644 --- a/pkg/object/tombstone.go +++ b/pkg/object/tombstone.go @@ -16,10 +16,22 @@ func NewTombstoneFromV2(tV2 *tombstone.Tombstone) *Tombstone { } // NewTombstone creates and initializes blank Tombstone. +// +// Defaults: +// - exp: 0; +// - splitID: nil; +// - members: nil. func NewTombstone() *Tombstone { return NewTombstoneFromV2(new(tombstone.Tombstone)) } +// ToV2 converts Tombstone to v2 Tombstone message. +// +// Nil Tombstone converts to nil. +func (ts *Tombstone) ToV2() *tombstone.Tombstone { + return (*tombstone.Tombstone)(ts) +} + // ExpirationEpoch return number of tombstone expiration epoch. func (t *Tombstone) ExpirationEpoch() uint64 { return (*tombstone.Tombstone)(t). diff --git a/pkg/object/tombstone_test.go b/pkg/object/tombstone_test.go index f9a0650..340fa2a 100644 --- a/pkg/object/tombstone_test.go +++ b/pkg/object/tombstone_test.go @@ -72,3 +72,21 @@ func TestNewTombstoneFromV2(t *testing.T) { require.Nil(t, NewTombstoneFromV2(x)) }) } + +func TestNewTombstone(t *testing.T) { + t.Run("default values", func(t *testing.T) { + ts := NewTombstone() + + // check initial values + require.Nil(t, ts.SplitID()) + require.Nil(t, ts.Members()) + require.Zero(t, ts.ExpirationEpoch()) + + // convert to v2 message + tsV2 := ts.ToV2() + + require.Nil(t, tsV2.GetSplitID()) + require.Nil(t, tsV2.GetMembers()) + require.Zero(t, tsV2.GetExpirationEpoch()) + }) +}