[#267] pkg: Fix IsSupportedVersion implementation

Current API library supports versions up to 2.4.x.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-17 14:20:04 +03:00 committed by Alex Vanin
parent 7cb9b8f283
commit 2fcb6d9613
2 changed files with 8 additions and 13 deletions

View file

@ -10,7 +10,7 @@ import (
// Version represents v2-compatible version. // Version represents v2-compatible version.
type Version refs.Version type Version refs.Version
const sdkMjr, sdkMnr = 2, 1 const sdkMjr, sdkMnr = 2, 4
// NewVersionFromV2 wraps v2 Version message to Version. // NewVersionFromV2 wraps v2 Version message to Version.
func NewVersionFromV2(v *refs.Version) *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. // IsSupportedVersion returns error if v is not supported by current SDK.
func IsSupportedVersion(v *Version) error { func IsSupportedVersion(v *Version) error {
switch mjr := v.Major(); mjr { mjr, mnr := v.Major(), v.Minor()
case 2:
switch mnr := v.Minor(); mnr { if mjr != 2 || mnr > sdkMnr {
case 0, 1: return errors.Errorf("unsupported version %d.%d", mjr, mnr)
return nil
}
} }
return errors.Errorf("unsupported version %d.%d", return nil
v.Major(),
v.Minor(),
)
} }
// Marshal marshals Version into a protobuf binary form. // Marshal marshals Version into a protobuf binary form.

View file

@ -46,12 +46,12 @@ func TestIsSupportedVersion(t *testing.T) {
}{ }{
{ {
mjr: 2, mjr: 2,
maxMnr: 1, maxMnr: sdkMnr,
}, },
} { } {
v.SetMajor(item.mjr) v.SetMajor(item.mjr)
for i := uint32(0); i < item.maxMnr; i++ { for i := uint32(0); i <= item.maxMnr; i++ {
v.SetMinor(i) v.SetMinor(i)
require.NoError(t, IsSupportedVersion(v)) require.NoError(t, IsSupportedVersion(v))