From 1542162657ae1a6222d738c9044b5b7dc73f685d Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 21:31:15 +0300 Subject: [PATCH] [#302] pkg/xheader: Document default values set in `NewXHeader` Document field values of instance constructed via `NewXHeader`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/xheader.go | 4 ++++ pkg/xheader_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/xheader.go b/pkg/xheader.go index 78786772..b36f1f01 100644 --- a/pkg/xheader.go +++ b/pkg/xheader.go @@ -15,6 +15,10 @@ func NewXHeaderFromV2(v *session.XHeader) *XHeader { } // NewXHeader creates, initializes and returns blank XHeader instance. +// +// Defaults: +// - key: ""; +// - value: "". func NewXHeader() *XHeader { return NewXHeaderFromV2(new(session.XHeader)) } diff --git a/pkg/xheader_test.go b/pkg/xheader_test.go index 66535bed..22cbe87d 100644 --- a/pkg/xheader_test.go +++ b/pkg/xheader_test.go @@ -40,3 +40,19 @@ func TestXHeader_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNewXHeader(t *testing.T) { + t.Run("default values", func(t *testing.T) { + xh := NewXHeader() + + // check initial values + require.Empty(t, xh.Value()) + require.Empty(t, xh.Key()) + + // convert to v2 message + xhV2 := xh.ToV2() + + require.Empty(t, xhV2.GetValue()) + require.Empty(t, xhV2.GetKey()) + }) +}