From 3bc25f54d8c15bcef36babccfbb4d9262b0870e8 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 20:44:26 +0300 Subject: [PATCH] [#302] pkg/storagegroup: Document default values set in `New` Document field values of instance constructed via `New`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/storagegroup/storagegroup.go | 6 ++++++ pkg/storagegroup/storagegroup_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/storagegroup/storagegroup.go b/pkg/storagegroup/storagegroup.go index c1994c3a..1a73a5a6 100644 --- a/pkg/storagegroup/storagegroup.go +++ b/pkg/storagegroup/storagegroup.go @@ -18,6 +18,12 @@ func NewFromV2(aV2 *storagegroup.StorageGroup) *StorageGroup { } // New creates and initializes blank StorageGroup. +// +// Defaults: +// - size: 0; +// - exp: 0; +// - members: nil; +// - hash: nil. func New() *StorageGroup { return NewFromV2(new(storagegroup.StorageGroup)) } diff --git a/pkg/storagegroup/storagegroup_test.go b/pkg/storagegroup/storagegroup_test.go index b89f5440..ee6c6a67 100644 --- a/pkg/storagegroup/storagegroup_test.go +++ b/pkg/storagegroup/storagegroup_test.go @@ -71,3 +71,23 @@ func TestStorageGroup_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNew(t *testing.T) { + t.Run("default values", func(t *testing.T) { + sg := storagegroup.New() + + // check initial values + require.Nil(t, sg.Members()) + require.Nil(t, sg.ValidationDataHash()) + require.Zero(t, sg.ExpirationEpoch()) + require.Zero(t, sg.ValidationDataSize()) + + // convert to v2 message + sgV2 := sg.ToV2() + + require.Nil(t, sgV2.GetMembers()) + require.Nil(t, sgV2.GetValidationHash()) + require.Zero(t, sgV2.GetExpirationEpoch()) + require.Zero(t, sgV2.GetValidationDataSize()) + }) +}