forked from TrueCloudLab/frostfs-api-go
[#149] sdk/object: Add address field getters and setters
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
7ef249f8db
commit
353448c0c3
2 changed files with 54 additions and 0 deletions
|
@ -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())
|
||||
}
|
||||
|
|
29
pkg/object/address_test.go
Normal file
29
pkg/object/address_test.go
Normal file
|
@ -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())
|
||||
}
|
Loading…
Reference in a new issue