frostfs-node/pkg/local_object_storage/engine/list_test.go
Leonard Lyubich 6f41cd86ed [#979] Upgrade SDK NeoFS Go dependency
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-12-01 17:31:04 +03:00

66 lines
1.5 KiB
Go

package engine
import (
"errors"
"os"
"sort"
"testing"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
"github.com/nspcc-dev/neofs-sdk-go/object"
"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([]*object.Address, 0, total)
got := make([]*object.Address, 0, total)
for i := 0; i < total; i++ {
containerID := cidtest.ID()
obj := generateRawObjectWithCID(t, containerID)
prm := new(PutPrm).WithObject(obj.Object())
_, err := e.Put(prm)
require.NoError(t, err)
expected = append(expected, obj.Object().Address())
}
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 []*object.Address) []*object.Address {
sort.Slice(addr, func(i, j int) bool {
return addr[i].String() < addr[j].String()
})
return addr
}