From 2176cb9f2b5ce31f2182ff84946dd8b83e8c5fa0 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 18:13:31 +0300 Subject: [PATCH] [#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 --- pkg/netmap/policy.go | 4 ++++ pkg/netmap/policy_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/netmap/policy.go b/pkg/netmap/policy.go index ce8a978f..27035536 100644 --- a/pkg/netmap/policy.go +++ b/pkg/netmap/policy.go @@ -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) } diff --git a/pkg/netmap/policy_test.go b/pkg/netmap/policy_test.go index 9fca579a..173317ab 100644 --- a/pkg/netmap/policy_test.go +++ b/pkg/netmap/policy_test.go @@ -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)) + }) +}