forked from TrueCloudLab/frostfs-api-go
[#302] pkg/netmap: Convert nil PlacementPolicy
to nil message
Document that `PlacementPolicy.ToV2` method return `nil` when called on `nil`. Document that `PlacementPolicyFromV2` function return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
df4d610fad
commit
2176cb9f2b
2 changed files with 20 additions and 0 deletions
|
@ -13,11 +13,15 @@ func NewPlacementPolicy() *PlacementPolicy {
|
|||
}
|
||||
|
||||
// NewPlacementPolicyFromV2 converts v2 PlacementPolicy to PlacementPolicy.
|
||||
//
|
||||
// Nil netmap.PlacementPolicy converts to nil.
|
||||
func NewPlacementPolicyFromV2(f *netmap.PlacementPolicy) *PlacementPolicy {
|
||||
return (*PlacementPolicy)(f)
|
||||
}
|
||||
|
||||
// ToV2 converts PlacementPolicy to v2 PlacementPolicy.
|
||||
//
|
||||
// Nil PlacementPolicy converts to nil.
|
||||
func (p *PlacementPolicy) ToV2() *netmap.PlacementPolicy {
|
||||
return (*netmap.PlacementPolicy)(p)
|
||||
}
|
||||
|
|
|
@ -144,3 +144,19 @@ func TestPlacementPolicyEncoding(t *testing.T) {
|
|||
require.Equal(t, p, p2)
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewPlacementPolicy(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
var x *PlacementPolicy
|
||||
|
||||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewPlacementPolicyFromV2(t *testing.T) {
|
||||
t.Run("from nil", func(t *testing.T) {
|
||||
var x *netmap.PlacementPolicy
|
||||
|
||||
require.Nil(t, NewPlacementPolicyFromV2(x))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue