[#302] pkg/object: Document default values set in NewAttribute

Document field values of instance constructed via `NewAttribute`.
Assert the values in corresponding unit test.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 18:52:49 +03:00 committed by Alex Vanin
parent 941b513eb3
commit ff851215b0
2 changed files with 20 additions and 0 deletions

View file

@ -17,6 +17,10 @@ func NewAttributeFromV2(aV2 *object.Attribute) *Attribute {
// NewAttribute creates and initializes blank Attribute. // NewAttribute creates and initializes blank Attribute.
// //
// Works similar as NewAttributeFromV2(new(Attribute)). // Works similar as NewAttributeFromV2(new(Attribute)).
//
// Defaults:
// - key: "";
// - value: "".
func NewAttribute() *Attribute { func NewAttribute() *Attribute {
return NewAttributeFromV2(new(object.Attribute)) return NewAttributeFromV2(new(object.Attribute))
} }

View file

@ -64,3 +64,19 @@ func TestAttribute_ToV2(t *testing.T) {
require.Nil(t, x.ToV2()) require.Nil(t, x.ToV2())
}) })
} }
func TestNewAttribute(t *testing.T) {
t.Run("default values", func(t *testing.T) {
a := NewAttribute()
// check initial values
require.Empty(t, a.Key())
require.Empty(t, a.Value())
// convert to v2 message
aV2 := a.ToV2()
require.Empty(t, aV2.GetKey())
require.Empty(t, aV2.GetValue())
})
}