forked from TrueCloudLab/frostfs-api-go
[#302] pkg/container: Convert nil Container
to nil message
Make `Container.ToV2` method to return `nil` when called on `nil`. Write corresponding unit test. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
3984353d37
commit
c08b90dbbc
2 changed files with 15 additions and 0 deletions
|
@ -44,7 +44,14 @@ func New(opts ...NewOption) *Container {
|
||||||
return cnr
|
return cnr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToV2 returns the v2 Container message.
|
||||||
|
//
|
||||||
|
// Nil Container converts to nil.
|
||||||
func (c *Container) ToV2() *container.Container {
|
func (c *Container) ToV2() *container.Container {
|
||||||
|
if c == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return &c.v2
|
return &c.v2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,3 +91,11 @@ func TestContainer_Signature(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, sig, cnr.Signature())
|
require.Equal(t, sig, cnr.Signature())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContainer_ToV2(t *testing.T) {
|
||||||
|
t.Run("nil", func(t *testing.T) {
|
||||||
|
var x *container.Container
|
||||||
|
|
||||||
|
require.Nil(t, x.ToV2())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue