diff --git a/client/object_delete.go b/client/object_delete.go index be2a52ad..175858e0 100644 --- a/client/object_delete.go +++ b/client/object_delete.go @@ -55,7 +55,7 @@ func (x *PrmObjectDelete) WithBearerToken(t bearer.Token) { } // FromContainer specifies NeoFS container of the object. -// Required parameter. +// Required parameter. It is an alternative to [PrmObjectDelete.ByAddress]. func (x *PrmObjectDelete) FromContainer(id cid.ID) { var cidV2 v2refs.ContainerID id.WriteToV2(&cidV2) @@ -64,7 +64,7 @@ func (x *PrmObjectDelete) FromContainer(id cid.ID) { } // ByID specifies identifier of the requested object. -// Required parameter. +// Required parameter. It is an alternative to [PrmObjectDelete.ByAddress]. func (x *PrmObjectDelete) ByID(id oid.ID) { var idV2 v2refs.ObjectID id.WriteToV2(&idV2) @@ -72,6 +72,12 @@ func (x *PrmObjectDelete) ByID(id oid.ID) { x.addr.SetObjectID(&idV2) } +// ByAddress specifies address of the requested object. +// Required parameter. It is an alternative to [PrmObjectDelete.ByID], [PrmObjectDelete.FromContainer]. +func (x *PrmObjectDelete) ByAddress(addr oid.Address) { + addr.WriteToV2(&x.addr) +} + // UseSigner specifies private signer to sign the requests. // If signer is not provided, then Client default signer is used. func (x *PrmObjectDelete) UseSigner(signer neofscrypto.Signer) { diff --git a/client/object_delete_test.go b/client/object_delete_test.go new file mode 100644 index 00000000..00b1bb1c --- /dev/null +++ b/client/object_delete_test.go @@ -0,0 +1,73 @@ +package client + +import ( + "bytes" + "crypto/rand" + "crypto/sha256" + "testing" + + v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/stretchr/testify/require" +) + +func randOID(t *testing.T) oid.ID { + var id oid.ID + id.SetSHA256(randSHA256Checksum(t)) + + return id +} + +func randCID(t *testing.T) cid.ID { + var id cid.ID + id.SetSHA256(randSHA256Checksum(t)) + + return id +} + +func randSHA256Checksum(t *testing.T) (cs [sha256.Size]byte) { + _, err := rand.Read(cs[:]) + require.NoError(t, err) + + return +} + +func TestPrmObjectDelete_ByAddress(t *testing.T) { + var prm PrmObjectDelete + + var ( + objID oid.ID + contID cid.ID + oidV2 v2refs.ObjectID + cidV2 v2refs.ContainerID + ) + + t.Run("ByID", func(t *testing.T) { + objID = randOID(t) + prm.ByID(objID) + + objID.WriteToV2(&oidV2) + + require.True(t, bytes.Equal(oidV2.GetValue(), prm.addr.GetObjectID().GetValue())) + }) + + t.Run("FromContainer", func(t *testing.T) { + contID = randCID(t) + prm.FromContainer(contID) + + contID.WriteToV2(&cidV2) + + require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue())) + }) + + t.Run("ByAddress", func(t *testing.T) { + var addr oid.Address + addr.SetObject(objID) + addr.SetContainer(contID) + + prm.ByAddress(addr) + require.True(t, bytes.Equal(oidV2.GetValue(), prm.addr.GetObjectID().GetValue())) + require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue())) + }) +} diff --git a/client/object_get.go b/client/object_get.go index 95dcb9f8..10587f7d 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -72,7 +72,7 @@ func (x *prmObjectRead) WithBearerToken(t bearer.Token) { } // FromContainer specifies NeoFS container of the object. -// Required parameter. +// Required parameter. It is an alternative to ByAddress. func (x *prmObjectRead) FromContainer(id cid.ID) { var cnrV2 v2refs.ContainerID id.WriteToV2(&cnrV2) @@ -80,13 +80,19 @@ func (x *prmObjectRead) FromContainer(id cid.ID) { } // ByID specifies identifier of the requested object. -// Required parameter. +// Required parameter. It is an alternative to ByAddress. func (x *prmObjectRead) ByID(id oid.ID) { var objV2 v2refs.ObjectID id.WriteToV2(&objV2) x.addr.SetObjectID(&objV2) } +// ByAddress specifies address of the requested object. +// Required parameter. It is an alternative to ByID, FromContainer. +func (x *prmObjectRead) ByAddress(addr oid.Address) { + addr.WriteToV2(&x.addr) +} + // PrmObjectGet groups parameters of ObjectGetInit operation. type PrmObjectGet struct { prmObjectRead diff --git a/client/object_get_test.go b/client/object_get_test.go new file mode 100644 index 00000000..13bf61ad --- /dev/null +++ b/client/object_get_test.go @@ -0,0 +1,50 @@ +package client + +import ( + "bytes" + "testing" + + v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/stretchr/testify/require" +) + +func TestPrmObjectRead_ByAddress(t *testing.T) { + var prm PrmObjectHead + + var ( + objID oid.ID + contID cid.ID + oidV2 v2refs.ObjectID + cidV2 v2refs.ContainerID + ) + + t.Run("ByID", func(t *testing.T) { + objID = randOID(t) + prm.ByID(objID) + + objID.WriteToV2(&oidV2) + + require.True(t, bytes.Equal(oidV2.GetValue(), prm.addr.GetObjectID().GetValue())) + }) + + t.Run("FromContainer", func(t *testing.T) { + contID = randCID(t) + prm.FromContainer(contID) + + contID.WriteToV2(&cidV2) + + require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue())) + }) + + t.Run("ByAddress", func(t *testing.T) { + var addr oid.Address + addr.SetObject(objID) + addr.SetContainer(contID) + + prm.ByAddress(addr) + require.True(t, bytes.Equal(oidV2.GetValue(), prm.addr.GetObjectID().GetValue())) + require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue())) + }) +} diff --git a/client/object_hash.go b/client/object_hash.go index 0e487ba7..72db77eb 100644 --- a/client/object_hash.go +++ b/client/object_hash.go @@ -67,7 +67,7 @@ func (x *PrmObjectHash) WithBearerToken(t bearer.Token) { } // FromContainer specifies NeoFS container of the object. -// Required parameter. +// Required parameter. It is an alternative to [PrmObjectHash.ByAddress]. func (x *PrmObjectHash) FromContainer(id cid.ID) { var cidV2 v2refs.ContainerID id.WriteToV2(&cidV2) @@ -76,7 +76,7 @@ func (x *PrmObjectHash) FromContainer(id cid.ID) { } // ByID specifies identifier of the requested object. -// Required parameter. +// Required parameter. It is an alternative to [PrmObjectHash.ByAddress]. func (x *PrmObjectHash) ByID(id oid.ID) { var idV2 v2refs.ObjectID id.WriteToV2(&idV2) @@ -84,6 +84,12 @@ func (x *PrmObjectHash) ByID(id oid.ID) { x.addr.SetObjectID(&idV2) } +// ByAddress specifies address of the requested object. +// Required parameter. It is an alternative to [PrmObjectHash.ByID], [PrmObjectHash.FromContainer]. +func (x *PrmObjectHash) ByAddress(addr oid.Address) { + addr.WriteToV2(&x.addr) +} + // SetRangeList sets list of ranges in (offset, length) pair format. // Required parameter. // diff --git a/client/object_hash_test.go b/client/object_hash_test.go new file mode 100644 index 00000000..695bbd89 --- /dev/null +++ b/client/object_hash_test.go @@ -0,0 +1,50 @@ +package client + +import ( + "bytes" + "testing" + + v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "github.com/stretchr/testify/require" +) + +func TestPrmObjectHash_ByAddress(t *testing.T) { + var prm PrmObjectHash + + var ( + objID oid.ID + contID cid.ID + oidV2 v2refs.ObjectID + cidV2 v2refs.ContainerID + ) + + t.Run("ByID", func(t *testing.T) { + objID = randOID(t) + prm.ByID(objID) + + objID.WriteToV2(&oidV2) + + require.True(t, bytes.Equal(oidV2.GetValue(), prm.addr.GetObjectID().GetValue())) + }) + + t.Run("FromContainer", func(t *testing.T) { + contID = randCID(t) + prm.FromContainer(contID) + + contID.WriteToV2(&cidV2) + + require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue())) + }) + + t.Run("ByAddress", func(t *testing.T) { + var addr oid.Address + addr.SetObject(objID) + addr.SetContainer(contID) + + prm.ByAddress(addr) + require.True(t, bytes.Equal(oidV2.GetValue(), prm.addr.GetObjectID().GetValue())) + require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue())) + }) +}