2020-08-13 12:43:47 +00:00
|
|
|
package container
|
2020-08-12 12:18:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-08-13 12:43:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2020-08-12 12:18:00 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
cnr = &Container{
|
|
|
|
OwnerId: &refs.OwnerID{Value: []byte("Owner")},
|
|
|
|
Nonce: []byte("Salt"),
|
|
|
|
BasicAcl: 505,
|
|
|
|
Attributes: []*Container_Attribute{
|
|
|
|
{
|
|
|
|
Key: "Hello",
|
|
|
|
Value: "World",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "Privet",
|
|
|
|
Value: "Mir",
|
|
|
|
},
|
|
|
|
},
|
2020-08-14 07:22:15 +00:00
|
|
|
PlacementPolicy: &netmap.PlacementPolicy{
|
2020-08-12 12:18:00 +00:00
|
|
|
ReplFactor: 4,
|
2020-08-14 07:22:15 +00:00
|
|
|
FilterGroups: []*netmap.PlacementPolicy_FilterGroup{
|
2020-08-12 12:18:00 +00:00
|
|
|
{
|
2020-08-14 07:22:15 +00:00
|
|
|
Selectors: []*netmap.PlacementPolicy_FilterGroup_Selector{
|
2020-08-12 12:18:00 +00:00
|
|
|
{
|
|
|
|
Count: 1,
|
|
|
|
Key: "Node",
|
|
|
|
},
|
|
|
|
},
|
2020-08-14 07:22:15 +00:00
|
|
|
Filters: []*netmap.PlacementPolicy_FilterGroup_Filter{
|
2020-08-12 12:18:00 +00:00
|
|
|
{
|
|
|
|
Key: "City",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "Datacenter",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Exclude: []uint32{4, 5, 6},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestContainer_StableMarshal(t *testing.T) {
|
|
|
|
newCnr := new(Container)
|
|
|
|
|
|
|
|
wire, err := cnr.StableMarshal(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = newCnr.Unmarshal(wire)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, cnr, newCnr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutRequest_Body_StableMarshal(t *testing.T) {
|
|
|
|
expectedBody := new(PutRequest_Body)
|
|
|
|
expectedBody.Container = cnr
|
|
|
|
expectedBody.PublicKey = []byte{1, 2, 3, 4}
|
|
|
|
expectedBody.Signature = []byte{5, 6, 7, 8}
|
|
|
|
|
|
|
|
wire, err := expectedBody.StableMarshal(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
gotBody := new(PutRequest_Body)
|
|
|
|
err = gotBody.Unmarshal(wire)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, expectedBody, gotBody)
|
|
|
|
}
|