forked from TrueCloudLab/frostfs-api-go
[#302] pkg/container/id: Document default values set in New
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
6ce8844654
commit
31ca5c14d3
2 changed files with 24 additions and 5 deletions
|
@ -20,6 +20,9 @@ func NewFromV2(idV2 *refs.ContainerID) *ID {
|
|||
}
|
||||
|
||||
// New creates and initializes blank ID.
|
||||
//
|
||||
// Defaults:
|
||||
// - value: nil.
|
||||
func New() *ID {
|
||||
return NewFromV2(new(refs.ContainerID))
|
||||
}
|
||||
|
@ -31,7 +34,7 @@ func (id *ID) SetSHA256(v [sha256.Size]byte) {
|
|||
|
||||
// ToV2 returns the v2 container ID message.
|
||||
//
|
||||
// Nil Result converts to nil.
|
||||
// Nil ID converts to nil.
|
||||
func (id *ID) ToV2() *refs.ContainerID {
|
||||
return (*refs.ContainerID)(id)
|
||||
}
|
||||
|
|
|
@ -33,6 +33,14 @@ func TestID_ToV2(t *testing.T) {
|
|||
|
||||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
|
||||
t.Run("default values", func(t *testing.T) {
|
||||
cid := cid.New()
|
||||
|
||||
// convert to v2 message
|
||||
cidV2 := cid.ToV2()
|
||||
require.Nil(t, cidV2.GetValue())
|
||||
})
|
||||
}
|
||||
|
||||
func TestID_Equal(t *testing.T) {
|
||||
|
@ -49,11 +57,19 @@ func TestID_Equal(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestID_String(t *testing.T) {
|
||||
t.Run("Parse/String", func(t *testing.T) {
|
||||
id := cidtest.Generate()
|
||||
id2 := cid.New()
|
||||
|
||||
require.NoError(t, id2.Parse(id.String()))
|
||||
require.Equal(t, id, id2)
|
||||
})
|
||||
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
id := cid.New()
|
||||
|
||||
require.Empty(t, id.String())
|
||||
})
|
||||
}
|
||||
|
||||
func TestContainerIDEncoding(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue