[#168] netmap: Implement binary and JSON encoders/decoders on Filter

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 11:45:59 +03:00 committed by Alex Vanin
parent 874a4b937f
commit e721734599
14 changed files with 628 additions and 196 deletions

View file

@ -13,96 +13,84 @@ import (
func TestAttribute_StableMarshal(t *testing.T) {
from := generateAttribute("key", "value")
transport := new(grpc.NodeInfo_Attribute)
t.Run("non empty", func(t *testing.T) {
wire, err := from.StableMarshal(nil)
require.NoError(t, err)
err = goproto.Unmarshal(wire, transport)
require.NoError(t, err)
to := new(netmap.Attribute)
require.NoError(t, to.Unmarshal(wire))
to := netmap.AttributeFromGRPCMessage(transport)
require.Equal(t, from, to)
})
}
func TestNodeInfo_StableMarshal(t *testing.T) {
from := generateNodeInfo("publicKey", "/multi/addr", 10)
transport := new(grpc.NodeInfo)
t.Run("non empty", func(t *testing.T) {
wire, err := from.StableMarshal(nil)
require.NoError(t, err)
err = goproto.Unmarshal(wire, transport)
require.NoError(t, err)
to := new(netmap.NodeInfo)
require.NoError(t, to.Unmarshal(wire))
to := netmap.NodeInfoFromGRPCMessage(transport)
require.Equal(t, from, to)
})
}
func TestFilter_StableMarshal(t *testing.T) {
from := generateFilter("key", "value", false)
transport := new(grpc.Filter)
t.Run("non empty", func(t *testing.T) {
wire, err := from.StableMarshal(nil)
require.NoError(t, err)
err = goproto.Unmarshal(wire, transport)
require.NoError(t, err)
to := new(netmap.Filter)
require.NoError(t, to.Unmarshal(wire))
to := netmap.FilterFromGRPCMessage(transport)
require.Equal(t, from, to)
})
}
func TestSelector_StableMarshal(t *testing.T) {
from := generateSelector("name")
transport := new(grpc.Selector)
t.Run("non empty", func(t *testing.T) {
wire, err := from.StableMarshal(nil)
require.NoError(t, err)
err = goproto.Unmarshal(wire, transport)
require.NoError(t, err)
to := new(netmap.Selector)
require.NoError(t, to.Unmarshal(wire))
to := netmap.SelectorFromGRPCMessage(transport)
require.Equal(t, from, to)
})
}
func TestReplica_StableMarshal(t *testing.T) {
from := generateReplica("selector")
transport := new(grpc.Replica)
t.Run("non empty", func(t *testing.T) {
wire, err := from.StableMarshal(nil)
require.NoError(t, err)
err = goproto.Unmarshal(wire, transport)
require.NoError(t, err)
to := new(netmap.Replica)
require.NoError(t, to.Unmarshal(wire))
to := netmap.ReplicaFromGRPCMessage(transport)
require.Equal(t, from, to)
})
}
func TestPlacementPolicy_StableMarshal(t *testing.T) {
from := generatePolicy(3)
transport := new(grpc.PlacementPolicy)
t.Run("non empty", func(t *testing.T) {
wire, err := from.StableMarshal(nil)
require.NoError(t, err)
err = goproto.Unmarshal(wire, transport)
require.NoError(t, err)
to := new(netmap.PlacementPolicy)
require.NoError(t, to.Unmarshal(wire))
to := netmap.PlacementPolicyFromGRPCMessage(transport)
require.Equal(t, from, to)
})
}