From dc99d4edce6d4b69b6b14e4cdadb3ebd5f75e1c6 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 21:25:35 +0300 Subject: [PATCH] [#302] pkg/version: Document default values set in `NewVersion` Document field values of instance constructed via `NewVersion`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/version.go | 4 ++++ pkg/version_test.go | 34 +++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pkg/version.go b/pkg/version.go index 68fd8e77..c38337df 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -21,6 +21,10 @@ func NewVersionFromV2(v *refs.Version) *Version { // NewVersion creates and initializes blank Version. // // Works similar as NewVersionFromV2(new(Version)). +// +// Defaults: +// - major: 0; +// - minor: 0. func NewVersion() *Version { return NewVersionFromV2(new(refs.Version)) } diff --git a/pkg/version_test.go b/pkg/version_test.go index fa756554..4586492e 100644 --- a/pkg/version_test.go +++ b/pkg/version_test.go @@ -8,20 +8,36 @@ import ( ) func TestNewVersion(t *testing.T) { - v := NewVersion() + t.Run("default values", func(t *testing.T) { + v := NewVersion() - var mjr, mnr uint32 = 1, 2 + // check initial values + require.Zero(t, v.Major()) + require.Zero(t, v.Minor()) - v.SetMajor(mjr) - v.SetMinor(mnr) + // convert to v2 message + vV2 := v.ToV2() - require.Equal(t, mjr, v.Major()) - require.Equal(t, mnr, v.Minor()) + require.Empty(t, vV2.GetMajor()) + require.Empty(t, vV2.GetMinor()) + }) - ver := v.ToV2() + t.Run("setting values", func(t *testing.T) { + v := NewVersion() - require.Equal(t, mjr, ver.GetMajor()) - require.Equal(t, mnr, ver.GetMinor()) + var mjr, mnr uint32 = 1, 2 + + v.SetMajor(mjr) + v.SetMinor(mnr) + + require.Equal(t, mjr, v.Major()) + require.Equal(t, mnr, v.Minor()) + + ver := v.ToV2() + + require.Equal(t, mjr, ver.GetMajor()) + require.Equal(t, mnr, ver.GetMinor()) + }) } func TestSDKVersion(t *testing.T) {