2020-11-05 10:28:29 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
2021-06-08 15:26:20 +00:00
|
|
|
testv2 "github.com/nspcc-dev/neofs-api-go/v2/netmap/test"
|
2020-11-05 10:28:29 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-11-05 11:08:19 +00:00
|
|
|
func testReplica() *Replica {
|
|
|
|
r := new(Replica)
|
|
|
|
r.SetCount(3)
|
|
|
|
r.SetSelector("selector")
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2020-11-05 10:28:29 +00:00
|
|
|
func TestReplicaFromV2(t *testing.T) {
|
2021-06-08 15:26:20 +00:00
|
|
|
t.Run("from nil", func(t *testing.T) {
|
|
|
|
var x *netmap.Replica
|
2020-11-05 10:28:29 +00:00
|
|
|
|
2021-06-08 15:26:20 +00:00
|
|
|
require.Nil(t, NewReplicaFromV2(x))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("from non-nil", func(t *testing.T) {
|
|
|
|
rV2 := testv2.GenerateReplica(false)
|
2020-11-05 10:28:29 +00:00
|
|
|
|
2021-06-08 15:26:20 +00:00
|
|
|
r := NewReplicaFromV2(rV2)
|
|
|
|
|
|
|
|
require.Equal(t, rV2, r.ToV2())
|
|
|
|
})
|
2020-11-05 10:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReplica_Count(t *testing.T) {
|
|
|
|
r := NewReplica()
|
|
|
|
c := uint32(3)
|
|
|
|
|
|
|
|
r.SetCount(c)
|
|
|
|
|
|
|
|
require.Equal(t, c, r.Count())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReplica_Selector(t *testing.T) {
|
|
|
|
r := NewReplica()
|
|
|
|
s := "some selector"
|
|
|
|
|
|
|
|
r.SetSelector(s)
|
|
|
|
|
|
|
|
require.Equal(t, s, r.Selector())
|
|
|
|
}
|
2020-11-13 08:45:59 +00:00
|
|
|
|
|
|
|
func TestReplicaEncoding(t *testing.T) {
|
|
|
|
r := newReplica(3, "selector")
|
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := r.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
r2 := NewReplica()
|
|
|
|
require.NoError(t, r2.Unmarshal(data))
|
|
|
|
|
|
|
|
require.Equal(t, r, r2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
|
|
data, err := r.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
r2 := NewReplica()
|
|
|
|
require.NoError(t, r2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, r, r2)
|
|
|
|
})
|
|
|
|
}
|
2021-06-08 15:26:20 +00:00
|
|
|
|
|
|
|
func TestReplica_ToV2(t *testing.T) {
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
var x *Replica
|
|
|
|
|
|
|
|
require.Nil(t, x.ToV2())
|
|
|
|
})
|
|
|
|
}
|