forked from TrueCloudLab/frostfs-sdk-go
Accept oid.Address into client.PrmObjectGet, PrmObjectHash, PrmObjectDelete (#408)
This commit is contained in:
commit
c97f834c6b
8 changed files with 288 additions and 22 deletions
|
@ -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) {
|
||||
|
|
73
client/object_delete_test.go
Normal file
73
client/object_delete_test.go
Normal file
|
@ -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()))
|
||||
})
|
||||
}
|
|
@ -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
|
||||
|
@ -479,17 +485,23 @@ type PrmObjectRange struct {
|
|||
}
|
||||
|
||||
// SetOffset sets offset of the payload range to be read.
|
||||
// Zero by default.
|
||||
// Zero by default. It is an alternative to [PrmObjectRange.SetRange].
|
||||
func (x *PrmObjectRange) SetOffset(off uint64) {
|
||||
x.rng.SetOffset(off)
|
||||
}
|
||||
|
||||
// SetLength sets length of the payload range to be read.
|
||||
// Must be positive.
|
||||
// Must be positive. It is an alternative to [PrmObjectRange.SetRange].
|
||||
func (x *PrmObjectRange) SetLength(ln uint64) {
|
||||
x.rng.SetLength(ln)
|
||||
}
|
||||
|
||||
// SetRange sets range of the payload to be read.
|
||||
// It is an alternative to [PrmObjectRange.SetOffset], [PrmObjectRange.SetLength].
|
||||
func (x *PrmObjectRange) SetRange(rng object.Range) {
|
||||
x.rng = *rng.ToV2()
|
||||
}
|
||||
|
||||
// UseSigner specifies private signer to sign the requests.
|
||||
// If signer is not provided, then Client default signer is used.
|
||||
func (x *PrmObjectRange) UseSigner(signer neofscrypto.Signer) {
|
||||
|
|
86
client/object_get_test.go
Normal file
86
client/object_get_test.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
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()))
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrmObjectRange_SetRange(t *testing.T) {
|
||||
var prm PrmObjectRange
|
||||
|
||||
var (
|
||||
ln = rand.Uint64()
|
||||
off = rand.Uint64()
|
||||
rng *object.Range
|
||||
)
|
||||
|
||||
t.Run("SetLength", func(t *testing.T) {
|
||||
prm.SetLength(ln)
|
||||
rng = object.NewRangeFromV2(&prm.rng)
|
||||
|
||||
require.Equal(t, ln, rng.GetLength())
|
||||
})
|
||||
|
||||
t.Run("SetOffset", func(t *testing.T) {
|
||||
prm.SetOffset(off)
|
||||
rng = object.NewRangeFromV2(&prm.rng)
|
||||
|
||||
require.Equal(t, off, rng.GetOffset())
|
||||
})
|
||||
|
||||
t.Run("SetRange", func(t *testing.T) {
|
||||
var tmp object.Range
|
||||
tmp.SetLength(ln)
|
||||
tmp.SetOffset(off)
|
||||
|
||||
prm.SetRange(tmp)
|
||||
require.Equal(t, ln, tmp.ToV2().GetLength())
|
||||
require.Equal(t, off, tmp.ToV2().GetOffset())
|
||||
})
|
||||
}
|
|
@ -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.
|
||||
//
|
||||
|
|
50
client/object_hash_test.go
Normal file
50
client/object_hash_test.go
Normal file
|
@ -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()))
|
||||
})
|
||||
}
|
31
pool/pool.go
31
pool/pool.go
|
@ -697,8 +697,7 @@ func (c *clientWrapper) objectDelete(ctx context.Context, prm PrmObjectDelete) e
|
|||
}
|
||||
|
||||
var cliPrm sdkClient.PrmObjectDelete
|
||||
cliPrm.FromContainer(prm.addr.Container())
|
||||
cliPrm.ByID(prm.addr.Object())
|
||||
cliPrm.ByAddress(prm.addr)
|
||||
|
||||
if prm.stoken != nil {
|
||||
cliPrm.WithinSession(*prm.stoken)
|
||||
|
@ -733,8 +732,7 @@ func (c *clientWrapper) objectGet(ctx context.Context, prm PrmObjectGet) (ResGet
|
|||
}
|
||||
|
||||
var cliPrm sdkClient.PrmObjectGet
|
||||
cliPrm.FromContainer(prm.addr.Container())
|
||||
cliPrm.ByID(prm.addr.Object())
|
||||
cliPrm.ByAddress(prm.addr)
|
||||
|
||||
if prm.stoken != nil {
|
||||
cliPrm.WithinSession(*prm.stoken)
|
||||
|
@ -786,8 +784,7 @@ func (c *clientWrapper) objectHead(ctx context.Context, prm PrmObjectHead) (obje
|
|||
}
|
||||
|
||||
var cliPrm sdkClient.PrmObjectHead
|
||||
cliPrm.FromContainer(prm.addr.Container())
|
||||
cliPrm.ByID(prm.addr.Object())
|
||||
cliPrm.ByAddress(prm.addr)
|
||||
if prm.raw {
|
||||
cliPrm.MarkRaw()
|
||||
}
|
||||
|
@ -831,10 +828,8 @@ func (c *clientWrapper) objectRange(ctx context.Context, prm PrmObjectRange) (Re
|
|||
}
|
||||
|
||||
var cliPrm sdkClient.PrmObjectRange
|
||||
cliPrm.FromContainer(prm.addr.Container())
|
||||
cliPrm.ByID(prm.addr.Object())
|
||||
cliPrm.SetOffset(prm.off)
|
||||
cliPrm.SetLength(prm.ln)
|
||||
cliPrm.ByAddress(prm.addr)
|
||||
cliPrm.SetRange(prm.rng)
|
||||
|
||||
if prm.stoken != nil {
|
||||
cliPrm.WithinSession(*prm.stoken)
|
||||
|
@ -1302,8 +1297,8 @@ func (x *PrmObjectHead) MarkRaw() {
|
|||
type PrmObjectRange struct {
|
||||
prmCommon
|
||||
|
||||
addr oid.Address
|
||||
off, ln uint64
|
||||
addr oid.Address
|
||||
rng object.Range
|
||||
}
|
||||
|
||||
// SetAddress specifies NeoFS address of the object.
|
||||
|
@ -1312,13 +1307,21 @@ func (x *PrmObjectRange) SetAddress(addr oid.Address) {
|
|||
}
|
||||
|
||||
// SetOffset sets offset of the payload range to be read.
|
||||
// Zero by default. It is an alternative to [PrmObjectRange.SetRange].
|
||||
func (x *PrmObjectRange) SetOffset(offset uint64) {
|
||||
x.off = offset
|
||||
x.rng.SetOffset(offset)
|
||||
}
|
||||
|
||||
// SetLength sets length of the payload range to be read.
|
||||
// Must be positive. It is an alternative to [PrmObjectRange.SetRange].
|
||||
func (x *PrmObjectRange) SetLength(length uint64) {
|
||||
x.ln = length
|
||||
x.rng.SetLength(length)
|
||||
}
|
||||
|
||||
// SetRange sets range of the payload to be read.
|
||||
// It is an alternative to [PrmObjectRange.SetOffset], [PrmObjectRange.SetLength].
|
||||
func (x *PrmObjectRange) SetRange(rng object.Range) {
|
||||
x.rng = rng
|
||||
}
|
||||
|
||||
// PrmObjectSearch groups parameters of SearchObjects operation.
|
||||
|
|
|
@ -3,6 +3,7 @@ package pool
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -655,3 +656,32 @@ func TestSwitchAfterErrorThreshold(t *testing.T) {
|
|||
_, err = conn.objectGet(ctx, PrmObjectGet{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestPrmObjectRange_SetRange(t *testing.T) {
|
||||
var prm PrmObjectRange
|
||||
|
||||
ln := rand.Uint64()
|
||||
off := rand.Uint64()
|
||||
|
||||
t.Run("SetLength", func(t *testing.T) {
|
||||
prm.SetLength(ln)
|
||||
|
||||
require.Equal(t, ln, prm.rng.ToV2().GetLength())
|
||||
})
|
||||
|
||||
t.Run("SetOffset", func(t *testing.T) {
|
||||
prm.SetOffset(off)
|
||||
|
||||
require.Equal(t, off, prm.rng.ToV2().GetOffset())
|
||||
})
|
||||
|
||||
t.Run("SetRange", func(t *testing.T) {
|
||||
var tmp object.Range
|
||||
tmp.SetLength(ln)
|
||||
tmp.SetOffset(off)
|
||||
|
||||
prm.SetRange(tmp)
|
||||
require.Equal(t, ln, tmp.ToV2().GetLength())
|
||||
require.Equal(t, off, tmp.ToV2().GetOffset())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue