From 3984353d3712fd9ab5833d58b371323021c12f52 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 15:33:42 +0300 Subject: [PATCH] [#302] pkg/container: 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/container/attribute.go | 5 +++++ pkg/container/attribute_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pkg/container/attribute.go b/pkg/container/attribute.go index 8964a048..2e4492fe 100644 --- a/pkg/container/attribute.go +++ b/pkg/container/attribute.go @@ -9,6 +9,11 @@ type ( Attributes []*Attribute ) +// NewAttribute creates and initializes blank Attribute. +// +// Defaults: +// - key: ""; +// - value: "". func NewAttribute() *Attribute { return NewAttributeFromV2(new(container.Attribute)) } diff --git a/pkg/container/attribute_test.go b/pkg/container/attribute_test.go index ea232867..e32dfda6 100644 --- a/pkg/container/attribute_test.go +++ b/pkg/container/attribute_test.go @@ -15,6 +15,19 @@ func TestAttribute(t *testing.T) { require.Nil(t, x.ToV2()) }) + t.Run("default values", func(t *testing.T) { + attr := container.NewAttribute() + + // check initial values + require.Empty(t, attr.Key()) + require.Empty(t, attr.Value()) + + // convert to v2 message + attrV2 := attr.ToV2() + require.Empty(t, attrV2.GetKey()) + require.Empty(t, attrV2.GetValue()) + }) + const ( key = "key" value = "value"