2020-11-11 14:21:55 +00:00
|
|
|
package container_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/acl"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2021-06-08 11:38:38 +00:00
|
|
|
containertest "github.com/nspcc-dev/neofs-api-go/pkg/container/test"
|
|
|
|
netmaptest "github.com/nspcc-dev/neofs-api-go/pkg/netmap/test"
|
|
|
|
ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
|
2021-05-31 12:09:04 +00:00
|
|
|
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
2021-06-08 11:38:38 +00:00
|
|
|
refstest "github.com/nspcc-dev/neofs-api-go/pkg/test"
|
2020-11-11 14:21:55 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewContainer(t *testing.T) {
|
|
|
|
c := container.New()
|
|
|
|
|
2020-12-24 09:26:41 +00:00
|
|
|
nonce := uuid.New()
|
2020-11-11 14:21:55 +00:00
|
|
|
|
2021-06-08 11:38:38 +00:00
|
|
|
ownerID := ownertest.Generate()
|
|
|
|
policy := netmaptest.PlacementPolicy()
|
2020-11-11 14:21:55 +00:00
|
|
|
|
|
|
|
c.SetBasicACL(acl.PublicBasicRule)
|
2021-06-08 11:38:38 +00:00
|
|
|
|
|
|
|
attrs := containertest.Attributes()
|
|
|
|
c.SetAttributes(attrs)
|
|
|
|
|
2020-11-11 14:21:55 +00:00
|
|
|
c.SetPlacementPolicy(policy)
|
2020-12-24 09:26:41 +00:00
|
|
|
c.SetNonceUUID(nonce)
|
2020-11-11 14:21:55 +00:00
|
|
|
c.SetOwnerID(ownerID)
|
2021-06-08 11:38:38 +00:00
|
|
|
|
|
|
|
ver := refstest.Version()
|
|
|
|
c.SetVersion(ver)
|
2020-11-11 14:21:55 +00:00
|
|
|
|
|
|
|
v2 := c.ToV2()
|
|
|
|
newContainer := container.NewContainerFromV2(v2)
|
|
|
|
|
|
|
|
require.EqualValues(t, newContainer.PlacementPolicy(), policy)
|
2021-06-08 11:38:38 +00:00
|
|
|
require.EqualValues(t, newContainer.Attributes(), attrs)
|
2020-11-11 14:21:55 +00:00
|
|
|
require.EqualValues(t, newContainer.BasicACL(), acl.PublicBasicRule)
|
2020-12-24 09:26:41 +00:00
|
|
|
|
|
|
|
newNonce, err := newContainer.NonceUUID()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.EqualValues(t, newNonce, nonce)
|
2020-11-11 14:21:55 +00:00
|
|
|
require.EqualValues(t, newContainer.OwnerID(), ownerID)
|
2021-06-08 11:38:38 +00:00
|
|
|
require.EqualValues(t, newContainer.Version(), ver)
|
2020-11-11 14:21:55 +00:00
|
|
|
}
|
2020-11-13 12:21:34 +00:00
|
|
|
|
|
|
|
func TestContainerEncoding(t *testing.T) {
|
2021-06-08 11:38:38 +00:00
|
|
|
c := containertest.Container()
|
2020-11-13 12:21:34 +00:00
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := c.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
c2 := container.New()
|
|
|
|
require.NoError(t, c2.Unmarshal(data))
|
|
|
|
|
|
|
|
require.Equal(t, c, c2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
|
|
data, err := c.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
c2 := container.New()
|
|
|
|
require.NoError(t, c2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, c, c2)
|
|
|
|
})
|
|
|
|
}
|
2021-05-24 16:48:41 +00:00
|
|
|
|
|
|
|
func TestContainer_SessionToken(t *testing.T) {
|
2021-05-31 12:09:04 +00:00
|
|
|
tok := sessiontest.Generate()
|
2021-05-24 16:48:41 +00:00
|
|
|
|
|
|
|
cnr := container.New()
|
|
|
|
|
|
|
|
cnr.SetSessionToken(tok)
|
|
|
|
|
|
|
|
require.Equal(t, tok, cnr.SessionToken())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContainer_Signature(t *testing.T) {
|
2021-06-08 11:38:38 +00:00
|
|
|
sig := refstest.Signature()
|
2021-05-24 16:48:41 +00:00
|
|
|
|
|
|
|
cnr := container.New()
|
|
|
|
cnr.SetSignature(sig)
|
|
|
|
|
|
|
|
require.Equal(t, sig, cnr.Signature())
|
|
|
|
}
|