From bf0d106e546ef085aaf0d840f3f5d7eb674d8c5a Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 21:09:06 +0300 Subject: [PATCH] [#302] pkg/checksum: Document default values set in `NewChecksum` Document field values of instance constructed via `NewChecksum`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/checksum.go | 8 ++++++-- pkg/checksum_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/checksum.go b/pkg/checksum.go index d8a91b7b..5d244b9e 100644 --- a/pkg/checksum.go +++ b/pkg/checksum.go @@ -34,9 +34,13 @@ func NewChecksumFromV2(cV2 *refs.Checksum) *Checksum { return (*Checksum)(cV2) } -// NewVersion creates and initializes blank Version. +// NewChecksum creates and initializes blank Checksum. // -// Works similar as NewVersionFromV2(new(Version)). +// Works similar as NewChecksumFromV2(new(Checksum)). +// +// Defaults: +// - sum: nil; +// - type: ChecksumUnknown. func NewChecksum() *Checksum { return NewChecksumFromV2(new(refs.Checksum)) } diff --git a/pkg/checksum_test.go b/pkg/checksum_test.go index 04343a92..e0508b80 100644 --- a/pkg/checksum_test.go +++ b/pkg/checksum_test.go @@ -115,3 +115,19 @@ func TestChecksum_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNewChecksum(t *testing.T) { + t.Run("default values", func(t *testing.T) { + chs := NewChecksum() + + // check initial values + require.Equal(t, ChecksumUnknown, chs.Type()) + require.Nil(t, chs.Sum()) + + // convert to v2 message + chsV2 := chs.ToV2() + + require.Equal(t, refs.UnknownChecksum, chsV2.GetType()) + require.Nil(t, chsV2.GetSum()) + }) +}