forked from TrueCloudLab/frostfs-api-go
[#302] pkg/container: Document default values set in New
Make `nil` as a default value for attributes. Document field values of instance constructed via `New`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
c08b90dbbc
commit
f92f9cd424
3 changed files with 46 additions and 2 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ func defaultContainerOptions() containerOptions {
|
|||
}
|
||||
|
||||
return containerOptions{
|
||||
acl: acl.PrivateBasicRule,
|
||||
nonce: rand,
|
||||
acl: acl.PrivateBasicRule,
|
||||
nonce: rand,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue