From 2fcb6d961335a7fd9676b3dad5e6f56bdf00f43a Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 17 Mar 2021 14:20:04 +0300 Subject: [PATCH] [#267] pkg: Fix IsSupportedVersion implementation Current API library supports versions up to 2.4.x. Signed-off-by: Leonard Lyubich --- pkg/version.go | 17 ++++++----------- pkg/version_test.go | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pkg/version.go b/pkg/version.go index 0c64956b..424dde90 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -10,7 +10,7 @@ import ( // Version represents v2-compatible version. type Version refs.Version -const sdkMjr, sdkMnr = 2, 1 +const sdkMjr, sdkMnr = 2, 4 // NewVersionFromV2 wraps v2 Version message to Version. func NewVersionFromV2(v *refs.Version) *Version { @@ -69,18 +69,13 @@ func (v *Version) String() string { // IsSupportedVersion returns error if v is not supported by current SDK. func IsSupportedVersion(v *Version) error { - switch mjr := v.Major(); mjr { - case 2: - switch mnr := v.Minor(); mnr { - case 0, 1: - return nil - } + mjr, mnr := v.Major(), v.Minor() + + if mjr != 2 || mnr > sdkMnr { + return errors.Errorf("unsupported version %d.%d", mjr, mnr) } - return errors.Errorf("unsupported version %d.%d", - v.Major(), - v.Minor(), - ) + return nil } // Marshal marshals Version into a protobuf binary form. diff --git a/pkg/version_test.go b/pkg/version_test.go index fe7f6617..2f5ee282 100644 --- a/pkg/version_test.go +++ b/pkg/version_test.go @@ -46,12 +46,12 @@ func TestIsSupportedVersion(t *testing.T) { }{ { mjr: 2, - maxMnr: 1, + maxMnr: sdkMnr, }, } { v.SetMajor(item.mjr) - for i := uint32(0); i < item.maxMnr; i++ { + for i := uint32(0); i <= item.maxMnr; i++ { v.SetMinor(i) require.NoError(t, IsSupportedVersion(v))