forked from TrueCloudLab/frostfs-api-go
[#295] pkg: Remove usage of deprecated elements
Remove usage of deprecated of `container.ID` and `token.SessionToken` code elements. Replace using of custom message generators with the ones provided by packages. Replace string comparison with `Equal` method call. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
89be8d3f5a
commit
65080c8b69
22 changed files with 97 additions and 209 deletions
|
@ -4,7 +4,7 @@ import (
|
|||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
)
|
||||
|
||||
|
@ -36,14 +36,14 @@ func (a *Address) ToV2() *refs.Address {
|
|||
}
|
||||
|
||||
// ContainerID returns container identifier.
|
||||
func (a *Address) ContainerID() *container.ID {
|
||||
return container.NewIDFromV2(
|
||||
func (a *Address) ContainerID() *cid.ID {
|
||||
return cid.NewFromV2(
|
||||
(*refs.Address)(a).GetContainerID(),
|
||||
)
|
||||
}
|
||||
|
||||
// SetContainerID sets container identifier.
|
||||
func (a *Address) SetContainerID(id *container.ID) {
|
||||
func (a *Address) SetContainerID(id *cid.ID) {
|
||||
(*refs.Address)(a).SetContainerID(id.ToV2())
|
||||
}
|
||||
|
||||
|
@ -64,20 +64,20 @@ func (a *Address) Parse(s string) error {
|
|||
var (
|
||||
err error
|
||||
oid = NewID()
|
||||
cid = container.NewID()
|
||||
id = cid.New()
|
||||
parts = strings.Split(s, addressSeparator)
|
||||
)
|
||||
|
||||
if len(parts) != addressParts {
|
||||
return errInvalidAddressString
|
||||
} else if err = cid.Parse(parts[0]); err != nil {
|
||||
} else if err = id.Parse(parts[0]); err != nil {
|
||||
return err
|
||||
} else if err = oid.Parse(parts[1]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.SetObjectID(oid)
|
||||
a.SetContainerID(cid)
|
||||
a.SetContainerID(id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,19 +4,18 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddress_SetContainerID(t *testing.T) {
|
||||
a := NewAddress()
|
||||
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(randSHA256Checksum(t))
|
||||
id := cidtest.Generate()
|
||||
|
||||
a.SetContainerID(cid)
|
||||
a.SetContainerID(id)
|
||||
|
||||
require.Equal(t, cid, a.ContainerID())
|
||||
require.Equal(t, id, a.ContainerID())
|
||||
}
|
||||
|
||||
func TestAddress_SetObjectID(t *testing.T) {
|
||||
|
@ -30,8 +29,7 @@ func TestAddress_SetObjectID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAddress_Parse(t *testing.T) {
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(randSHA256Checksum(t))
|
||||
cid := cidtest.Generate()
|
||||
|
||||
oid := NewID()
|
||||
oid.SetSHA256(randSHA256Checksum(t))
|
||||
|
@ -64,7 +62,7 @@ func TestAddress_Parse(t *testing.T) {
|
|||
func TestAddressEncoding(t *testing.T) {
|
||||
a := NewAddress()
|
||||
a.SetObjectID(randID(t))
|
||||
a.SetContainerID(randCID(t))
|
||||
a.SetContainerID(cidtest.Generate())
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
data, err := a.Marshal()
|
||||
|
|
|
@ -2,9 +2,9 @@ package object
|
|||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
)
|
||||
|
||||
|
@ -71,7 +71,7 @@ func (o *RawObject) SetPayloadSize(v uint64) {
|
|||
}
|
||||
|
||||
// SetContainerID sets identifier of the related container.
|
||||
func (o *RawObject) SetContainerID(v *container.ID) {
|
||||
func (o *RawObject) SetContainerID(v *cid.ID) {
|
||||
o.setContainerID(v)
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ func (o *RawObject) SetParent(v *Object) {
|
|||
|
||||
// SetSessionToken sets token of the session
|
||||
// within which object was created.
|
||||
func (o *RawObject) SetSessionToken(v *token.SessionToken) {
|
||||
func (o *RawObject) SetSessionToken(v *session.Token) {
|
||||
o.setSessionToken(v)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
|
||||
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -20,13 +20,6 @@ func randID(t *testing.T) *ID {
|
|||
return id
|
||||
}
|
||||
|
||||
func randCID(t *testing.T) *container.ID {
|
||||
id := container.NewID()
|
||||
id.SetSHA256(randSHA256Checksum(t))
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func randSHA256Checksum(t *testing.T) (cs [sha256.Size]byte) {
|
||||
_, err := rand.Read(cs[:])
|
||||
require.NoError(t, err)
|
||||
|
@ -98,10 +91,7 @@ func TestRawObject_SetPayloadSize(t *testing.T) {
|
|||
func TestRawObject_SetContainerID(t *testing.T) {
|
||||
obj := NewRaw()
|
||||
|
||||
checksum := randSHA256Checksum(t)
|
||||
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(checksum)
|
||||
cid := cidtest.Generate()
|
||||
|
||||
obj.SetContainerID(cid)
|
||||
|
||||
|
@ -111,11 +101,7 @@ func TestRawObject_SetContainerID(t *testing.T) {
|
|||
func TestRawObject_SetOwnerID(t *testing.T) {
|
||||
obj := NewRaw()
|
||||
|
||||
w := new(owner.NEO3Wallet)
|
||||
_, _ = rand.Read(w.Bytes())
|
||||
|
||||
ownerID := owner.NewID()
|
||||
ownerID.SetNeo3Wallet(w)
|
||||
ownerID := ownertest.Generate()
|
||||
|
||||
obj.SetOwnerID(ownerID)
|
||||
|
||||
|
@ -208,7 +194,7 @@ func TestRawObject_SetParent(t *testing.T) {
|
|||
|
||||
par := NewRaw()
|
||||
par.SetID(randID(t))
|
||||
par.SetContainerID(container.NewID())
|
||||
par.SetContainerID(cidtest.Generate())
|
||||
par.SetSignature(pkg.NewSignature())
|
||||
|
||||
parObj := par.Object()
|
||||
|
@ -230,8 +216,7 @@ func TestRawObject_ToV2(t *testing.T) {
|
|||
func TestRawObject_SetSessionToken(t *testing.T) {
|
||||
obj := NewRaw()
|
||||
|
||||
tok := token.NewSessionToken()
|
||||
tok.SetID([]byte{1, 2, 3})
|
||||
tok := sessiontest.Generate()
|
||||
|
||||
obj.SetSessionToken(tok)
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ package object
|
|||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
)
|
||||
|
@ -108,15 +108,15 @@ func (o *rwObject) setPayloadSize(v uint64) {
|
|||
}
|
||||
|
||||
// ContainerID returns identifier of the related container.
|
||||
func (o *rwObject) ContainerID() *container.ID {
|
||||
return container.NewIDFromV2(
|
||||
func (o *rwObject) ContainerID() *cid.ID {
|
||||
return cid.NewFromV2(
|
||||
(*object.Object)(o).
|
||||
GetHeader().
|
||||
GetContainerID(),
|
||||
)
|
||||
}
|
||||
|
||||
func (o *rwObject) setContainerID(v *container.ID) {
|
||||
func (o *rwObject) setContainerID(v *cid.ID) {
|
||||
o.setHeaderField(func(h *object.Header) {
|
||||
h.SetContainerID(v.ToV2())
|
||||
})
|
||||
|
@ -327,15 +327,15 @@ func (o *rwObject) resetRelations() {
|
|||
|
||||
// SessionToken returns token of the session
|
||||
// within which object was created.
|
||||
func (o *rwObject) SessionToken() *token.SessionToken {
|
||||
return token.NewSessionTokenFromV2(
|
||||
func (o *rwObject) SessionToken() *session.Token {
|
||||
return session.NewTokenFromV2(
|
||||
(*object.Object)(o).
|
||||
GetHeader().
|
||||
GetSessionToken(),
|
||||
)
|
||||
}
|
||||
|
||||
func (o *rwObject) setSessionToken(v *token.SessionToken) {
|
||||
func (o *rwObject) setSessionToken(v *session.Token) {
|
||||
o.setHeaderField(func(h *object.Header) {
|
||||
h.SetSessionToken(v.ToV2())
|
||||
})
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
)
|
||||
|
@ -199,7 +199,7 @@ func (f *SearchFilters) AddObjectVersionFilter(op SearchMatchType, v *pkg.Versio
|
|||
f.addReservedFilter(op, fKeyVersion, v)
|
||||
}
|
||||
|
||||
func (f *SearchFilters) AddObjectContainerIDFilter(m SearchMatchType, id *container.ID) {
|
||||
func (f *SearchFilters) AddObjectContainerIDFilter(m SearchMatchType, id *cid.ID) {
|
||||
f.addReservedFilter(m, fKeyContainerID, id)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue