From c00cdd407d7562d00a79feb8485ac7a19b5d3403 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 19:51:34 +0300 Subject: [PATCH] [#302] pkg/owner: Document default values set in `NewID` Document field values of instance constructed via `NewID`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/owner/id.go | 3 +++ pkg/owner/id_test.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/owner/id.go b/pkg/owner/id.go index fadb8181..3ba53000 100644 --- a/pkg/owner/id.go +++ b/pkg/owner/id.go @@ -25,6 +25,9 @@ func NewIDFromV2(idV2 *refs.OwnerID) *ID { // NewID creates and initializes blank ID. // // Works similar as NewIDFromV2(new(OwnerID)). +// +// Defaults: +// - value: nil. func NewID() *ID { return NewIDFromV2(new(refs.OwnerID)) } diff --git a/pkg/owner/id_test.go b/pkg/owner/id_test.go index d32b8952..f5cff068 100644 --- a/pkg/owner/id_test.go +++ b/pkg/owner/id_test.go @@ -116,3 +116,22 @@ func TestID_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestID_String(t *testing.T) { + t.Run("nil", func(t *testing.T) { + id := NewID() + + require.Empty(t, id.String()) + }) +} + +func TestNewID(t *testing.T) { + t.Run("default values", func(t *testing.T) { + id := NewID() + + // convert to v2 message + idV2 := id.ToV2() + + require.Nil(t, idV2.GetValue()) + }) +}