[#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 <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 14:33:56 +03:00 committed by Alex Vanin
parent 4e2ef6a30a
commit 821e2951b6
2 changed files with 21 additions and 0 deletions

View file

@ -12,6 +12,8 @@ import (
type Result audit.DataAuditResult type Result audit.DataAuditResult
// NewFromV2 wraps v2 DataAuditResult message to Result. // NewFromV2 wraps v2 DataAuditResult message to Result.
//
// Nil audit.DataAuditResult converts to nil.
func NewResultFromV2(aV2 *audit.DataAuditResult) *Result { func NewResultFromV2(aV2 *audit.DataAuditResult) *Result {
return (*Result)(aV2) return (*Result)(aV2)
} }
@ -25,6 +27,8 @@ func NewResult() *Result {
} }
// ToV2 converts Result to v2 DataAuditResult message. // ToV2 converts Result to v2 DataAuditResult message.
//
// Nil Result converts to nil.
func (r *Result) ToV2() *audit.DataAuditResult { func (r *Result) ToV2() *audit.DataAuditResult {
return (*audit.DataAuditResult)(r) return (*audit.DataAuditResult)(r)
} }

View file

@ -9,6 +9,7 @@ import (
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test" 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" "github.com/stretchr/testify/require"
) )
@ -91,3 +92,19 @@ func TestStorageGroupEncoding(t *testing.T) {
require.Equal(t, r, r2) 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))
})
}