All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
* Introduce testEngineWrapper that can be constructed with different options Signed-off-by: Airat Arifullin a.arifullin@yadro.com
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package engine
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"sort"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestListWithCursor(t *testing.T) {
|
|
s1 := testNewShard(t, 1)
|
|
s2 := testNewShard(t, 2)
|
|
e := testNewEngine(t).setInitializedShards(t, s1, s2).engine
|
|
|
|
t.Cleanup(func() {
|
|
e.Close()
|
|
os.RemoveAll(t.Name())
|
|
})
|
|
|
|
const total = 20
|
|
|
|
expected := make([]object.AddressWithType, 0, total)
|
|
got := make([]object.AddressWithType, 0, total)
|
|
|
|
for i := 0; i < total; i++ {
|
|
containerID := cidtest.ID()
|
|
obj := testutil.GenerateObjectWithCID(containerID)
|
|
|
|
var prm PutPrm
|
|
prm.WithObject(obj)
|
|
|
|
_, err := e.Put(prm)
|
|
require.NoError(t, err)
|
|
expected = append(expected, object.AddressWithType{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)})
|
|
}
|
|
|
|
expected = sortAddresses(expected)
|
|
|
|
var prm ListWithCursorPrm
|
|
prm.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++ {
|
|
prm.WithCursor(res.Cursor())
|
|
|
|
res, err = e.ListWithCursor(prm)
|
|
if errors.Is(err, ErrEndOfListing) {
|
|
break
|
|
}
|
|
got = append(got, res.AddressList()...)
|
|
}
|
|
|
|
prm.WithCursor(res.Cursor())
|
|
|
|
_, err = e.ListWithCursor(prm)
|
|
require.ErrorIs(t, err, ErrEndOfListing)
|
|
|
|
got = sortAddresses(got)
|
|
require.Equal(t, expected, got)
|
|
}
|
|
|
|
func sortAddresses(addrWithType []object.AddressWithType) []object.AddressWithType {
|
|
sort.Slice(addrWithType, func(i, j int) bool {
|
|
return addrWithType[i].Address.EncodeToString() < addrWithType[j].Address.EncodeToString()
|
|
})
|
|
return addrWithType
|
|
}
|