From dde721ea9f19f492fe8266f382172fa748217841 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 19:31:26 +0300 Subject: [PATCH] [#302] pkg/object: Document default values set in `NewSplitInfo` Document field values of instance constructed via `NewSplitInfo`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/object/splitinfo.go | 6 ++++++ pkg/object/splitinfo_test.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/object/splitinfo.go b/pkg/object/splitinfo.go index cbe71620..38ae3081 100644 --- a/pkg/object/splitinfo.go +++ b/pkg/object/splitinfo.go @@ -13,6 +13,12 @@ func NewSplitInfoFromV2(v2 *object.SplitInfo) *SplitInfo { return (*SplitInfo)(v2) } +// NewSplitInfo creates and initializes blank SplitInfo. +// +// Defaults: +// - splitID: nil; +// - lastPart nil; +// - link: nil. func NewSplitInfo() *SplitInfo { return NewSplitInfoFromV2(new(object.SplitInfo)) } diff --git a/pkg/object/splitinfo_test.go b/pkg/object/splitinfo_test.go index 62387101..500f5ba2 100644 --- a/pkg/object/splitinfo_test.go +++ b/pkg/object/splitinfo_test.go @@ -68,3 +68,21 @@ func TestSplitInfo_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNewSplitInfo(t *testing.T) { + t.Run("default values", func(t *testing.T) { + si := object.NewSplitInfo() + + // check initial values + require.Nil(t, si.SplitID()) + require.Nil(t, si.LastPart()) + require.Nil(t, si.Link()) + + // convert to v2 message + siV2 := si.ToV2() + + require.Nil(t, siV2.GetSplitID()) + require.Nil(t, siV2.GetLastPart()) + require.Nil(t, siV2.GetLink()) + }) +}