2021-10-27 14:51:58 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2021-11-10 11:07:57 +00:00
|
|
|
"errors"
|
2021-10-27 14:51:58 +00:00
|
|
|
"os"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2021-10-27 14:51:58 +00:00
|
|
|
"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
|
|
|
|
|
2022-11-12 13:48:44 +00:00
|
|
|
expected := make([]object.AddressWithType, 0, total)
|
|
|
|
got := make([]object.AddressWithType, 0, total)
|
2021-10-27 14:51:58 +00:00
|
|
|
|
|
|
|
for i := 0; i < total; i++ {
|
2021-12-01 13:56:48 +00:00
|
|
|
containerID := cidtest.ID()
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := generateObjectWithCID(t, containerID)
|
2022-05-23 13:12:32 +00:00
|
|
|
|
|
|
|
var prm PutPrm
|
|
|
|
prm.WithObject(obj)
|
|
|
|
|
2021-10-27 14:51:58 +00:00
|
|
|
_, err := e.Put(prm)
|
|
|
|
require.NoError(t, err)
|
2022-11-12 13:48:44 +00:00
|
|
|
expected = append(expected, object.AddressWithType{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)})
|
2021-10-27 14:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected = sortAddresses(expected)
|
|
|
|
|
2022-05-23 13:12:32 +00:00
|
|
|
var prm ListWithCursorPrm
|
|
|
|
prm.WithCount(1)
|
|
|
|
|
2021-11-10 11:07:57 +00:00
|
|
|
res, err := e.ListWithCursor(prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, res.AddressList())
|
|
|
|
got = append(got, res.AddressList()...)
|
2021-10-27 14:51:58 +00:00
|
|
|
|
2021-11-10 11:07:57 +00:00
|
|
|
for i := 0; i < total-1; i++ {
|
2022-05-23 13:12:32 +00:00
|
|
|
prm.WithCursor(res.Cursor())
|
|
|
|
|
|
|
|
res, err = e.ListWithCursor(prm)
|
2021-11-17 11:31:31 +00:00
|
|
|
if errors.Is(err, ErrEndOfListing) {
|
2021-11-10 11:07:57 +00:00
|
|
|
break
|
|
|
|
}
|
2021-10-27 14:51:58 +00:00
|
|
|
got = append(got, res.AddressList()...)
|
|
|
|
}
|
|
|
|
|
2022-05-23 13:12:32 +00:00
|
|
|
prm.WithCursor(res.Cursor())
|
|
|
|
|
|
|
|
_, err = e.ListWithCursor(prm)
|
2021-11-17 11:31:31 +00:00
|
|
|
require.ErrorIs(t, err, ErrEndOfListing)
|
2021-11-10 11:07:57 +00:00
|
|
|
|
2021-10-27 14:51:58 +00:00
|
|
|
got = sortAddresses(got)
|
|
|
|
require.Equal(t, expected, got)
|
|
|
|
}
|
|
|
|
|
2022-11-12 13:48:44 +00:00
|
|
|
func sortAddresses(addrWithType []object.AddressWithType) []object.AddressWithType {
|
|
|
|
sort.Slice(addrWithType, func(i, j int) bool {
|
|
|
|
return addrWithType[i].Address.EncodeToString() < addrWithType[j].Address.EncodeToString()
|
2021-10-27 14:51:58 +00:00
|
|
|
})
|
2022-11-12 13:48:44 +00:00
|
|
|
return addrWithType
|
2021-10-27 14:51:58 +00:00
|
|
|
}
|