From ff851215b080e43ea3a7eb10f0b8844a24782fb6 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 18:52:49 +0300 Subject: [PATCH] [#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 --- pkg/object/attribute.go | 4 ++++ pkg/object/attribute_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/object/attribute.go b/pkg/object/attribute.go index 23be55d2..7f366865 100644 --- a/pkg/object/attribute.go +++ b/pkg/object/attribute.go @@ -17,6 +17,10 @@ func NewAttributeFromV2(aV2 *object.Attribute) *Attribute { // NewAttribute creates and initializes blank Attribute. // // Works similar as NewAttributeFromV2(new(Attribute)). +// +// Defaults: +// - key: ""; +// - value: "". func NewAttribute() *Attribute { return NewAttributeFromV2(new(object.Attribute)) } diff --git a/pkg/object/attribute_test.go b/pkg/object/attribute_test.go index 05735b75..d5f1b3f9 100644 --- a/pkg/object/attribute_test.go +++ b/pkg/object/attribute_test.go @@ -64,3 +64,19 @@ func TestAttribute_ToV2(t *testing.T) { 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()) + }) +}