frostfs-api-go/v2/netmap/json_test.go
Alex Vanin e4d94bbe03 [#186] v2/netmap: Add JSON converter for placement policy
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2020-11-05 10:38:04 +03:00

52 lines
1.1 KiB
Go

package netmap_test
import (
"testing"
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/stretchr/testify/require"
)
func TestNodeInfoJSON(t *testing.T) {
exp := generateNodeInfo("public key", "/multi/addr", 2)
t.Run("non empty", func(t *testing.T) {
data, err := netmap.NodeInfoToJSON(exp)
require.NoError(t, err)
got, err := netmap.NodeInfoFromJSON(data)
require.NoError(t, err)
require.Equal(t, exp, got)
})
t.Run("empty", func(t *testing.T) {
_, err := netmap.NodeInfoToJSON(nil)
require.Error(t, err)
_, err = netmap.NodeInfoFromJSON(nil)
require.Error(t, err)
})
}
func TestPlacementPolicyJSON(t *testing.T) {
exp := generatePolicy(3)
t.Run("non empty", func(t *testing.T) {
data, err := netmap.PlacementPolicyToJSON(exp)
require.NoError(t, err)
got, err := netmap.PlacementPolicyFromJSON(data)
require.NoError(t, err)
require.Equal(t, exp, got)
})
t.Run("empty", func(t *testing.T) {
_, err := netmap.PlacementPolicyToJSON(nil)
require.Error(t, err)
_, err = netmap.PlacementPolicyFromJSON(nil)
require.Error(t, err)
})
}