[#139] object: Implement function to init object creation
All NeoFS object must have at least container and owner identifiers. Add `InitCreation` function which write all required fields to the object instance. Extend `Object` type docs with all the constructors. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
1c161956c8
commit
df5c69eea5
2 changed files with 48 additions and 3 deletions
|
@ -12,11 +12,32 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/version"
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Object represents v2-compatible NeoFS object that provides
|
// Object represents in-memory structure of the NeoFS object.
|
||||||
// a convenient interface for working in isolation
|
// Type is compatible with NeoFS API V2 protocol.
|
||||||
// from the internal structure of an object.
|
//
|
||||||
|
// Instance can be created depending on scenario:
|
||||||
|
// * InitCreation (an object to be placed in container);
|
||||||
|
// * New (blank instance, usually needed for decoding);
|
||||||
|
// * NewFromV2 (when working under NeoFS API V2 protocol).
|
||||||
type Object object.Object
|
type Object object.Object
|
||||||
|
|
||||||
|
// RequiredFields contains the minimum set of object data that must be set
|
||||||
|
// by the NeoFS user at the stage of creation.
|
||||||
|
type RequiredFields struct {
|
||||||
|
// Identifier of the NeoFS container associated with the object.
|
||||||
|
Container cid.ID
|
||||||
|
|
||||||
|
// Object owner ID in the NeoFS system.
|
||||||
|
Owner owner.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitCreation initializes the object instance with minimum set of required fields.
|
||||||
|
// Object is expected (but not required) to be blank. Object must not be nil.
|
||||||
|
func InitCreation(dst *Object, rf RequiredFields) {
|
||||||
|
dst.SetContainerID(&rf.Container)
|
||||||
|
dst.SetOwnerID(&rf.Owner)
|
||||||
|
}
|
||||||
|
|
||||||
// NewFromV2 wraps v2 Object message to Object.
|
// NewFromV2 wraps v2 Object message to Object.
|
||||||
func NewFromV2(oV2 *object.Object) *Object {
|
func NewFromV2(oV2 *object.Object) *Object {
|
||||||
return (*Object)(oV2)
|
return (*Object)(oV2)
|
||||||
|
|
24
object/object_test.go
Normal file
24
object/object_test.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package object_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitCreation(t *testing.T) {
|
||||||
|
var o object.Object
|
||||||
|
cnr := *cidtest.ID()
|
||||||
|
own := *ownertest.ID()
|
||||||
|
|
||||||
|
object.InitCreation(&o, object.RequiredFields{
|
||||||
|
Container: cnr,
|
||||||
|
Owner: own,
|
||||||
|
})
|
||||||
|
|
||||||
|
require.Equal(t, &cnr, o.ContainerID())
|
||||||
|
require.Equal(t, &own, o.OwnerID())
|
||||||
|
}
|
Loading…
Reference in a new issue