forked from TrueCloudLab/frostfs-api-go
[#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:
parent
4e2ef6a30a
commit
821e2951b6
2 changed files with 21 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue