frostfs-api-go-pogpp/v2/netmap/json_test.go
Leonard Lyubich 9eda317efe [#259] netmap: Implement JSON encoding for NetworkInfo RPC messages
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-02-19 16:25:53 +03:00

80 lines
1.5 KiB
Go

package netmap_test
import (
"testing"
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/stretchr/testify/require"
)
func TestFilterJSON(t *testing.T) {
f := generateFilter("key", "value", false)
d, err := f.MarshalJSON()
require.NoError(t, err)
f2 := new(netmap.Filter)
require.NoError(t, f2.UnmarshalJSON(d))
require.Equal(t, f, f2)
}
func TestSelectorJSON(t *testing.T) {
s := generateSelector("name")
data, err := s.MarshalJSON()
require.NoError(t, err)
s2 := new(netmap.Selector)
require.NoError(t, s2.UnmarshalJSON(data))
require.Equal(t, s, s2)
}
func TestReplicaJSON(t *testing.T) {
s := generateReplica("selector")
data, err := s.MarshalJSON()
require.NoError(t, err)
s2 := new(netmap.Replica)
require.NoError(t, s2.UnmarshalJSON(data))
require.Equal(t, s, s2)
}
func TestAttributeJSON(t *testing.T) {
a := generateAttribute("key", "value")
data, err := a.MarshalJSON()
require.NoError(t, err)
a2 := new(netmap.Attribute)
require.NoError(t, a2.UnmarshalJSON(data))
require.Equal(t, a, a2)
}
func TestNodeInfoJSON(t *testing.T) {
i := generateNodeInfo("key", "value", 3)
data, err := i.MarshalJSON()
require.NoError(t, err)
i2 := new(netmap.NodeInfo)
require.NoError(t, i2.UnmarshalJSON(data))
require.Equal(t, i, i2)
}
func TestNetworkInfoJSON(t *testing.T) {
i := generateNetworkInfo()
data, err := i.MarshalJSON()
require.NoError(t, err)
i2 := new(netmap.NetworkInfo)
require.NoError(t, i2.UnmarshalJSON(data))
require.Equal(t, i, i2)
}