2020-09-10 11:29:11 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-06-08 18:22:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2020-09-10 11:29:11 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-06-08 18:22:33 +00:00
|
|
|
func TestNewVersion(t *testing.T) {
|
2020-09-10 11:29:11 +00:00
|
|
|
v := NewVersion()
|
|
|
|
|
|
|
|
var mjr, mnr uint32 = 1, 2
|
|
|
|
|
|
|
|
v.SetMajor(mjr)
|
|
|
|
v.SetMinor(mnr)
|
|
|
|
|
2020-11-16 08:08:47 +00:00
|
|
|
require.Equal(t, mjr, v.Major())
|
|
|
|
require.Equal(t, mnr, v.Minor())
|
2020-09-10 11:29:11 +00:00
|
|
|
|
|
|
|
ver := v.ToV2()
|
|
|
|
|
|
|
|
require.Equal(t, mjr, ver.GetMajor())
|
|
|
|
require.Equal(t, mnr, ver.GetMinor())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSDKVersion(t *testing.T) {
|
|
|
|
v := SDKVersion()
|
|
|
|
|
2020-11-16 08:08:47 +00:00
|
|
|
require.Equal(t, uint32(sdkMjr), v.Major())
|
|
|
|
require.Equal(t, uint32(sdkMnr), v.Minor())
|
2020-09-10 11:29:11 +00:00
|
|
|
}
|
2020-11-03 08:29:41 +00:00
|
|
|
|
|
|
|
func TestIsSupportedVersion(t *testing.T) {
|
|
|
|
require.Error(t, IsSupportedVersion(nil))
|
|
|
|
|
|
|
|
v := NewVersion()
|
|
|
|
|
|
|
|
v.SetMajor(1)
|
|
|
|
require.Error(t, IsSupportedVersion(v))
|
|
|
|
|
|
|
|
v.SetMajor(3)
|
|
|
|
require.Error(t, IsSupportedVersion(v))
|
|
|
|
|
|
|
|
for _, item := range []struct {
|
|
|
|
mjr, maxMnr uint32
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
mjr: 2,
|
2021-03-17 11:20:04 +00:00
|
|
|
maxMnr: sdkMnr,
|
2020-11-03 08:29:41 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
v.SetMajor(item.mjr)
|
|
|
|
|
2021-03-17 11:20:04 +00:00
|
|
|
for i := uint32(0); i <= item.maxMnr; i++ {
|
2020-11-03 08:29:41 +00:00
|
|
|
v.SetMinor(i)
|
|
|
|
|
|
|
|
require.NoError(t, IsSupportedVersion(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
v.SetMinor(item.maxMnr + 1)
|
|
|
|
|
|
|
|
require.Error(t, IsSupportedVersion(v))
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 13:19:16 +00:00
|
|
|
|
|
|
|
func TestVersionEncoding(t *testing.T) {
|
|
|
|
v := NewVersion()
|
|
|
|
v.SetMajor(1)
|
|
|
|
v.SetMinor(2)
|
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := v.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
v2 := NewVersion()
|
|
|
|
require.NoError(t, v2.Unmarshal(data))
|
|
|
|
|
|
|
|
require.Equal(t, v, v2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
|
|
data, err := v.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
v2 := NewVersion()
|
|
|
|
require.NoError(t, v2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, v, v2)
|
|
|
|
})
|
|
|
|
}
|
2021-06-08 18:22:33 +00:00
|
|
|
|
|
|
|
func TestNewVersionFromV2(t *testing.T) {
|
|
|
|
t.Run("from nil", func(t *testing.T) {
|
|
|
|
var x *refs.Version
|
|
|
|
|
|
|
|
require.Nil(t, NewVersionFromV2(x))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVersion_ToV2(t *testing.T) {
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
var x *Version
|
|
|
|
|
|
|
|
require.Nil(t, x.ToV2())
|
|
|
|
})
|
|
|
|
}
|