frostfs-node/pkg/local_object_storage/engine/list_test.go
Leonard Lyubich 7ccd1625af [#1214] *: Use single Object type in whole project
Remove `Object` and `RawObject` types from `pkg/core/object` package.
Use `Object` type from NeoFS SDK Go library everywhere. Avoid using the
deprecated elements.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-03-04 17:45:00 +03:00

67 lines
1.6 KiB
Go

package engine
import (
"errors"
"os"
"sort"
"testing"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
"github.com/stretchr/testify/require"
)
func TestListWithCursor(t *testing.T) {
s1 := testNewShard(t, 1)
s2 := testNewShard(t, 2)
e := testNewEngineWithShards(s1, s2)
t.Cleanup(func() {
e.Close()
os.RemoveAll(t.Name())
})
const total = 20
expected := make([]*addressSDK.Address, 0, total)
got := make([]*addressSDK.Address, 0, total)
for i := 0; i < total; i++ {
containerID := cidtest.ID()
obj := generateObjectWithCID(t, containerID)
prm := new(PutPrm).WithObject(obj)
_, err := e.Put(prm)
require.NoError(t, err)
expected = append(expected, object.AddressOf(obj))
}
expected = sortAddresses(expected)
prm := new(ListWithCursorPrm).WithCount(1)
res, err := e.ListWithCursor(prm)
require.NoError(t, err)
require.NotEmpty(t, res.AddressList())
got = append(got, res.AddressList()...)
for i := 0; i < total-1; i++ {
res, err = e.ListWithCursor(prm.WithCursor(res.Cursor()))
if errors.Is(err, ErrEndOfListing) {
break
}
got = append(got, res.AddressList()...)
}
_, err = e.ListWithCursor(prm.WithCursor(res.Cursor()))
require.ErrorIs(t, err, ErrEndOfListing)
got = sortAddresses(got)
require.Equal(t, expected, got)
}
func sortAddresses(addr []*addressSDK.Address) []*addressSDK.Address {
sort.Slice(addr, func(i, j int) bool {
return addr[i].String() < addr[j].String()
})
return addr
}