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
|
@ -1,6 +1,7 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||
)
|
||||
|
||||
|
@ -30,14 +31,14 @@ func (a *UsedSpaceAnnouncement) SetEpoch(epoch uint64) {
|
|||
}
|
||||
|
||||
// ContainerID of the announcement.
|
||||
func (a *UsedSpaceAnnouncement) ContainerID() *ID {
|
||||
return NewIDFromV2(
|
||||
func (a *UsedSpaceAnnouncement) ContainerID() *cid.ID {
|
||||
return cid.NewFromV2(
|
||||
(*container.UsedSpaceAnnouncement)(a).GetContainerID(),
|
||||
)
|
||||
}
|
||||
|
||||
// SetContainerID sets announcement container value.
|
||||
func (a *UsedSpaceAnnouncement) SetContainerID(cid *ID) {
|
||||
func (a *UsedSpaceAnnouncement) SetContainerID(cid *cid.ID) {
|
||||
(*container.UsedSpaceAnnouncement)(a).SetContainerID(cid.ToV2())
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -12,18 +14,17 @@ import (
|
|||
func TestAnnouncement(t *testing.T) {
|
||||
const epoch, usedSpace uint64 = 10, 100
|
||||
|
||||
cidValue := [32]byte{1, 2, 3}
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(cidValue)
|
||||
cidValue := [sha256.Size]byte{1, 2, 3}
|
||||
id := cidtest.GenerateWithChecksum(cidValue)
|
||||
|
||||
a := container.NewAnnouncement()
|
||||
a.SetEpoch(epoch)
|
||||
a.SetContainerID(cid)
|
||||
a.SetContainerID(id)
|
||||
a.SetUsedSpace(usedSpace)
|
||||
|
||||
require.Equal(t, epoch, a.Epoch())
|
||||
require.Equal(t, usedSpace, a.UsedSpace())
|
||||
require.Equal(t, cid, a.ContainerID())
|
||||
require.Equal(t, id, a.ContainerID())
|
||||
|
||||
t.Run("test v2", func(t *testing.T) {
|
||||
const newEpoch, newUsedSpace uint64 = 20, 200
|
||||
|
@ -45,7 +46,7 @@ func TestAnnouncement(t *testing.T) {
|
|||
|
||||
require.Equal(t, newEpoch, newA.Epoch())
|
||||
require.Equal(t, newUsedSpace, newA.UsedSpace())
|
||||
require.Equal(t, container.NewIDFromV2(newCID), newA.ContainerID())
|
||||
require.Equal(t, cid.NewFromV2(newCID), newA.ContainerID())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -54,8 +55,7 @@ func TestUsedSpaceEncoding(t *testing.T) {
|
|||
a.SetUsedSpace(13)
|
||||
a.SetEpoch(666)
|
||||
|
||||
id := container.NewID()
|
||||
id.SetSHA256([sha256.Size]byte{1, 2, 3})
|
||||
id := cidtest.Generate()
|
||||
|
||||
a.SetContainerID(id)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
|
@ -63,13 +64,13 @@ func NewContainerFromV2(c *container.Container) *Container {
|
|||
|
||||
// CalculateID calculates container identifier
|
||||
// based on its structure.
|
||||
func CalculateID(c *Container) *ID {
|
||||
func CalculateID(c *Container) *cid.ID {
|
||||
data, err := c.ToV2().StableMarshal(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
id := NewID()
|
||||
id := cid.New()
|
||||
id.SetSHA256(sha256.Sum256(data))
|
||||
|
||||
return id
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
||||
"github.com/nspcc-dev/neofs-crypto/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -98,8 +98,7 @@ func TestContainerEncoding(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContainer_SessionToken(t *testing.T) {
|
||||
tok := token.NewSessionToken()
|
||||
tok.SetID([]byte{1, 2, 3})
|
||||
tok := sessiontest.Generate()
|
||||
|
||||
cnr := container.New()
|
||||
|
||||
|
|
|
@ -16,11 +16,9 @@ func randSHA256Checksum() (cs [sha256.Size]byte) {
|
|||
}
|
||||
|
||||
func TestID_ToV2(t *testing.T) {
|
||||
id := cid.New()
|
||||
|
||||
checksum := randSHA256Checksum()
|
||||
|
||||
id.SetSHA256(checksum)
|
||||
id := cidtest.GenerateWithChecksum(checksum)
|
||||
|
||||
idV2 := id.ToV2()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue