forked from TrueCloudLab/frostfs-api-go
[#302] pkg/object: Convert nil Attribute
to nil message
Document that `Attribute.ToV2` method return `nil` when called on `nil`. Document that `NewAttributeFromV2` 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
5fda8ef796
commit
941b513eb3
2 changed files with 21 additions and 0 deletions
|
@ -8,6 +8,8 @@ import (
|
|||
type Attribute object.Attribute
|
||||
|
||||
// NewAttributeFromV2 wraps v2 Attribute message to Attribute.
|
||||
//
|
||||
// Nil object.Attribute converts to nil.
|
||||
func NewAttributeFromV2(aV2 *object.Attribute) *Attribute {
|
||||
return (*Attribute)(aV2)
|
||||
}
|
||||
|
@ -40,6 +42,8 @@ func (a *Attribute) SetValue(v string) {
|
|||
}
|
||||
|
||||
// ToV2 converts Attribute to v2 Attribute message.
|
||||
//
|
||||
// Nil Attribute converts to nil.
|
||||
func (a *Attribute) ToV2() *object.Attribute {
|
||||
return (*object.Attribute)(a)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package object
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -47,3 +48,19 @@ func TestAttributeEncoding(t *testing.T) {
|
|||
require.Equal(t, a, a2)
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewAttributeFromV2(t *testing.T) {
|
||||
t.Run("from nil", func(t *testing.T) {
|
||||
var x *object.Attribute
|
||||
|
||||
require.Nil(t, NewAttributeFromV2(x))
|
||||
})
|
||||
}
|
||||
|
||||
func TestAttribute_ToV2(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
var x *Attribute
|
||||
|
||||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue