From 353448c0c365325d51a7c46df4a116ac097005a5 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 17 Sep 2020 13:16:43 +0300 Subject: [PATCH] [#149] sdk/object: Add address field getters and setters Signed-off-by: Leonard Lyubich --- pkg/object/address.go | 25 +++++++++++++++++++++++++ pkg/object/address_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 pkg/object/address_test.go diff --git a/pkg/object/address.go b/pkg/object/address.go index af8271a4..0c50e4f0 100644 --- a/pkg/object/address.go +++ b/pkg/object/address.go @@ -1,6 +1,7 @@ package object import ( + "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/pkg/errors" ) @@ -34,3 +35,27 @@ func AddressFromBytes(data []byte) (*Address, error) { return NewAddressFromV2(addrV2), nil } + +// GetContainerID returns container identifier. +func (a *Address) GetContainerID() *container.ID { + return container.NewIDFromV2( + (*refs.Address)(a).GetContainerID(), + ) +} + +// SetContainerID sets container identifier. +func (a *Address) SetContainerID(id *container.ID) { + (*refs.Address)(a).SetContainerID(id.ToV2()) +} + +// GetObjectID returns object identifier. +func (a *Address) GetObjectID() *ID { + return NewIDFromV2( + (*refs.Address)(a).GetObjectID(), + ) +} + +// SetObjectID sets object identifier. +func (a *Address) SetObjectID(id *ID) { + (*refs.Address)(a).SetObjectID(id.ToV2()) +} diff --git a/pkg/object/address_test.go b/pkg/object/address_test.go new file mode 100644 index 00000000..d286ed48 --- /dev/null +++ b/pkg/object/address_test.go @@ -0,0 +1,29 @@ +package object + +import ( + "testing" + + "github.com/nspcc-dev/neofs-api-go/pkg/container" + "github.com/stretchr/testify/require" +) + +func TestAddress_SetContainerID(t *testing.T) { + a := NewAddress() + + cid := container.NewID() + cid.SetSHA256(randSHA256Checksum(t)) + + a.SetContainerID(cid) + + require.Equal(t, cid, a.GetContainerID()) +} + +func TestAddress_SetObjectID(t *testing.T) { + a := NewAddress() + + oid := randID(t) + + a.SetObjectID(oid) + + require.Equal(t, oid, a.GetObjectID()) +}