forked from TrueCloudLab/frostfs-api-go
[#259] pkg/netmap: Implement v2-compatible NetworkInfo type
Define NetworkInfo structure. Implement constructors, fields getters and setters, binary and JSON encoding methods. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
88d6857a3c
commit
f6268339d0
2 changed files with 133 additions and 0 deletions
53
pkg/netmap/network_info_test.go
Normal file
53
pkg/netmap/network_info_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package netmap
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNetworkInfo_CurrentEpoch(t *testing.T) {
|
||||
i := NewNetworkInfo()
|
||||
e := uint64(13)
|
||||
|
||||
i.SetCurrentEpoch(e)
|
||||
|
||||
require.Equal(t, e, i.CurrentEpoch())
|
||||
require.Equal(t, e, i.ToV2().GetCurrentEpoch())
|
||||
}
|
||||
|
||||
func TestNetworkInfo_MagicNumber(t *testing.T) {
|
||||
i := NewNetworkInfo()
|
||||
m := uint64(666)
|
||||
|
||||
i.SetMagicNumber(m)
|
||||
|
||||
require.Equal(t, m, i.MagicNumber())
|
||||
require.Equal(t, m, i.ToV2().GetMagicNumber())
|
||||
}
|
||||
|
||||
func TestNetworkInfoEncoding(t *testing.T) {
|
||||
i := NewNetworkInfo()
|
||||
i.SetCurrentEpoch(13)
|
||||
i.SetMagicNumber(666)
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
data, err := i.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
i2 := NewNetworkInfo()
|
||||
require.NoError(t, i2.Unmarshal(data))
|
||||
|
||||
require.Equal(t, i, i2)
|
||||
})
|
||||
|
||||
t.Run("json", func(t *testing.T) {
|
||||
data, err := i.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
i2 := NewNetworkInfo()
|
||||
require.NoError(t, i2.UnmarshalJSON(data))
|
||||
|
||||
require.Equal(t, i, i2)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue