diff --git a/pkg/container/container.go b/pkg/container/container.go index 24ed218d..7ae7fe4c 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -20,6 +20,17 @@ type Container struct { sig *pkg.Signature } +// New creates, initializes and returns blank Container instance. +// +// Defaults: +// - token: nil; +// - sig: nil; +// - basicACL: acl.PrivateBasicRule; +// - version: nil; +// - nonce: random UUID; +// - attr: nil; +// - policy: nil; +// - ownerID: nil. func New(opts ...NewOption) *Container { cnrOptions := defaultContainerOptions() diff --git a/pkg/container/container_test.go b/pkg/container/container_test.go index 1a1bce39..a5175b52 100644 --- a/pkg/container/container_test.go +++ b/pkg/container/container_test.go @@ -98,4 +98,37 @@ func TestContainer_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) + + t.Run("default values", func(t *testing.T) { + cnt := container.New() + + // check initial values + require.Nil(t, cnt.SessionToken()) + require.Nil(t, cnt.Signature()) + require.Nil(t, cnt.Version()) + require.Nil(t, cnt.Attributes()) + require.Nil(t, cnt.PlacementPolicy()) + require.Nil(t, cnt.OwnerID()) + + require.EqualValues(t, acl.PrivateBasicRule, cnt.BasicACL()) + + nonce, err := cnt.NonceUUID() + require.NoError(t, err) + require.NotNil(t, nonce) + + // convert to v2 message + cntV2 := cnt.ToV2() + + nonceV2, err := uuid.FromBytes(cntV2.GetNonce()) + require.NoError(t, err) + + require.Equal(t, nonce.String(), nonceV2.String()) + + require.Nil(t, cntV2.GetVersion()) + require.Nil(t, cntV2.GetAttributes()) + require.Nil(t, cntV2.GetPlacementPolicy()) + require.Nil(t, cntV2.GetOwnerID()) + + require.Equal(t, uint32(acl.PrivateBasicRule), cntV2.GetBasicACL()) + }) } diff --git a/pkg/container/opts.go b/pkg/container/opts.go index 8c15ed1f..d07b6846 100644 --- a/pkg/container/opts.go +++ b/pkg/container/opts.go @@ -28,8 +28,8 @@ func defaultContainerOptions() containerOptions { } return containerOptions{ - acl: acl.PrivateBasicRule, - nonce: rand, + acl: acl.PrivateBasicRule, + nonce: rand, } }