From 5fda8ef796854e39a485ca596143fef1cdf6a512 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 18:48:20 +0300 Subject: [PATCH] [#302] pkg/object: Document default values set in `NewAddress` Document field values of instance constructed via `NewAddress`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy --- pkg/object/address.go | 4 ++++ pkg/object/address_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/object/address.go b/pkg/object/address.go index 54d550fd..f1072a9e 100644 --- a/pkg/object/address.go +++ b/pkg/object/address.go @@ -28,6 +28,10 @@ func NewAddressFromV2(aV2 *refs.Address) *Address { // NewAddress creates and initializes blank Address. // // Works similar as NewAddressFromV2(new(Address)). +// +// Defaults: +// - cid: nil; +// - oid: nil. func NewAddress() *Address { return NewAddressFromV2(new(refs.Address)) } diff --git a/pkg/object/address_test.go b/pkg/object/address_test.go index f3b8b35e..6d97cb75 100644 --- a/pkg/object/address_test.go +++ b/pkg/object/address_test.go @@ -101,3 +101,19 @@ func TestAddress_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNewAddress(t *testing.T) { + t.Run("default values", func(t *testing.T) { + a := NewAddress() + + // check initial values + require.Nil(t, a.ContainerID()) + require.Nil(t, a.ObjectID()) + + // convert to v2 message + aV2 := a.ToV2() + + require.Nil(t, aV2.GetContainerID()) + require.Nil(t, aV2.GetObjectID()) + }) +}