[#302] pkg/object: Document default values set in NewTombstone

Document field values of instance constructed via `NewTombstone`.
Assert the values in corresponding unit test.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 19:43:26 +03:00 committed by Alex Vanin
parent 753402c336
commit 2fb67d99d3
2 changed files with 30 additions and 0 deletions

View file

@ -16,10 +16,22 @@ func NewTombstoneFromV2(tV2 *tombstone.Tombstone) *Tombstone {
} }
// NewTombstone creates and initializes blank Tombstone. // NewTombstone creates and initializes blank Tombstone.
//
// Defaults:
// - exp: 0;
// - splitID: nil;
// - members: nil.
func NewTombstone() *Tombstone { func NewTombstone() *Tombstone {
return NewTombstoneFromV2(new(tombstone.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. // ExpirationEpoch return number of tombstone expiration epoch.
func (t *Tombstone) ExpirationEpoch() uint64 { func (t *Tombstone) ExpirationEpoch() uint64 {
return (*tombstone.Tombstone)(t). return (*tombstone.Tombstone)(t).

View file

@ -72,3 +72,21 @@ func TestNewTombstoneFromV2(t *testing.T) {
require.Nil(t, NewTombstoneFromV2(x)) 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())
})
}