From 821e2951b6c1f7f7f472d8528b8774f4292586d7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 14:33:56 +0300 Subject: [PATCH] [#302] pkg/audit: Convert nil `Result` to nil message Document that `Result.ToV2` method returns `nil` when is called on `nil`. Document that `NewResultFromV2` method returns `nil` when is called on `nil`. Add corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/audit/result.go | 4 ++++ pkg/audit/result_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/audit/result.go b/pkg/audit/result.go index 047e40a8..1ff1dc06 100644 --- a/pkg/audit/result.go +++ b/pkg/audit/result.go @@ -12,6 +12,8 @@ import ( type Result audit.DataAuditResult // NewFromV2 wraps v2 DataAuditResult message to Result. +// +// Nil audit.DataAuditResult converts to nil. func NewResultFromV2(aV2 *audit.DataAuditResult) *Result { return (*Result)(aV2) } @@ -25,6 +27,8 @@ func NewResult() *Result { } // ToV2 converts Result to v2 DataAuditResult message. +// +// Nil Result converts to nil. func (r *Result) ToV2() *audit.DataAuditResult { return (*audit.DataAuditResult)(r) } diff --git a/pkg/audit/result_test.go b/pkg/audit/result_test.go index 49081ce6..fc0ce375 100644 --- a/pkg/audit/result_test.go +++ b/pkg/audit/result_test.go @@ -9,6 +9,7 @@ import ( cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-api-go/pkg/object" objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test" + auditv2 "github.com/nspcc-dev/neofs-api-go/v2/audit" "github.com/stretchr/testify/require" ) @@ -91,3 +92,19 @@ func TestStorageGroupEncoding(t *testing.T) { require.Equal(t, r, r2) }) } + +func TestResult_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *audit.Result + + require.Nil(t, x.ToV2()) + }) +} + +func TestNewResultFromV2(t *testing.T) { + t.Run("from nil", func(t *testing.T) { + var x *auditv2.DataAuditResult + + require.Nil(t, audit.NewResultFromV2(x)) + }) +}