Skip to content

Commit

Permalink
[#267] pkg: Fix IsSupportedVersion implementation
Browse files Browse the repository at this point in the history
Current API library supports versions up to 2.4.x.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
Leonard Lyubich authored and alexvanin committed Mar 17, 2021
1 parent 7cb9b8f commit 2fcb6d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
17 changes: 6 additions & 11 deletions pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 2fcb6d9

Please sign in to comment.