From 1863694b9657986d2515215f7215f4987d56818e Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 15:25:41 +0300 Subject: [PATCH] [#302] pkg/container: Document default values set in `NewAnnouncement` Document field values of instance constructed via `NewAnnouncement`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/container/announcement.go | 5 +++++ pkg/container/announcement_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/container/announcement.go b/pkg/container/announcement.go index 20041aa4..cfa9510b 100644 --- a/pkg/container/announcement.go +++ b/pkg/container/announcement.go @@ -10,6 +10,11 @@ import ( type UsedSpaceAnnouncement container.UsedSpaceAnnouncement // NewAnnouncement initialize empty UsedSpaceAnnouncement message. +// +// Defaults: +// - epoch: 0; +// - usedSpace: 0; +// - cid: nil. func NewAnnouncement() *UsedSpaceAnnouncement { return NewAnnouncementFromV2(new(container.UsedSpaceAnnouncement)) } diff --git a/pkg/container/announcement_test.go b/pkg/container/announcement_test.go index 3560ae6a..dc669b89 100644 --- a/pkg/container/announcement_test.go +++ b/pkg/container/announcement_test.go @@ -72,6 +72,22 @@ func TestUsedSpaceAnnouncement_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) + + t.Run("default values", func(t *testing.T) { + announcement := container.NewAnnouncement() + + // check initial values + require.Zero(t, announcement.Epoch()) + require.Zero(t, announcement.UsedSpace()) + require.Nil(t, announcement.ContainerID()) + + // convert to v2 message + announcementV2 := announcement.ToV2() + + require.Zero(t, announcementV2.GetEpoch()) + require.Zero(t, announcementV2.GetUsedSpace()) + require.Nil(t, announcementV2.GetContainerID()) + }) } func TestNewAnnouncementFromV2(t *testing.T) {