Revert "[#972] Use require.ElementsMatch() where possible"

This reverts commit 6d9707ff1f.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-02-19 17:02:56 +03:00 committed by Evgenii Stratonikov
parent 3359349acb
commit 7627d08914
3 changed files with 35 additions and 3 deletions

View file

@ -3,6 +3,7 @@ package engine
import ( import (
"context" "context"
"path/filepath" "path/filepath"
"sort"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -17,6 +18,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
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
}
func TestListWithCursor(t *testing.T) { func TestListWithCursor(t *testing.T) {
t.Parallel() t.Parallel()
@ -90,6 +98,7 @@ func TestListWithCursor(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
expected = append(expected, object.AddressWithType{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)}) expected = append(expected, object.AddressWithType{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)})
} }
expected = sortAddresses(expected)
var prm ListWithCursorPrm var prm ListWithCursorPrm
prm.count = tt.batchSize prm.count = tt.batchSize
@ -104,7 +113,8 @@ func TestListWithCursor(t *testing.T) {
prm.cursor = res.Cursor() prm.cursor = res.Cursor()
} }
require.ElementsMatch(t, expected, got) got = sortAddresses(got)
require.Equal(t, expected, got)
}) })
} }
} }

View file

@ -3,6 +3,7 @@ package meta_test
import ( import (
"context" "context"
"math/rand" "math/rand"
"sort"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -124,9 +125,18 @@ func TestDB_ContainersCount(t *testing.T) {
} }
} }
sort.Slice(expected, func(i, j int) bool {
return expected[i].EncodeToString() < expected[j].EncodeToString()
})
got, err := db.Containers(context.Background()) got, err := db.Containers(context.Background())
require.NoError(t, err) require.NoError(t, err)
require.ElementsMatch(t, expected, got)
sort.Slice(got, func(i, j int) bool {
return got[i].EncodeToString() < got[j].EncodeToString()
})
require.Equal(t, expected, got)
} }
func TestDB_ContainerSize(t *testing.T) { func TestDB_ContainerSize(t *testing.T) {

View file

@ -3,6 +3,7 @@ package meta_test
import ( import (
"context" "context"
"errors" "errors"
"sort"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -127,6 +128,8 @@ func TestLisObjectsWithCursor(t *testing.T) {
expected = append(expected, object.AddressWithType{Address: object.AddressOf(child), Type: objectSDK.TypeRegular}) expected = append(expected, object.AddressWithType{Address: object.AddressOf(child), Type: objectSDK.TypeRegular})
} }
expected = sortAddresses(expected)
t.Run("success with various count", func(t *testing.T) { t.Run("success with various count", func(t *testing.T) {
for countPerReq := 1; countPerReq <= total; countPerReq++ { for countPerReq := 1; countPerReq <= total; countPerReq++ {
got := make([]object.AddressWithType, 0, total) got := make([]object.AddressWithType, 0, total)
@ -148,7 +151,9 @@ func TestLisObjectsWithCursor(t *testing.T) {
_, _, err = metaListWithCursor(db, uint32(countPerReq), cursor) _, _, err = metaListWithCursor(db, uint32(countPerReq), cursor)
require.ErrorIs(t, err, meta.ErrEndOfListing, "count:%d", countPerReq, cursor) require.ErrorIs(t, err, meta.ErrEndOfListing, "count:%d", countPerReq, cursor)
require.ElementsMatch(t, expected, got, "count:%d", countPerReq)
got = sortAddresses(got)
require.Equal(t, expected, got, "count:%d", countPerReq)
} }
}) })
@ -211,6 +216,13 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) {
} }
} }
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
}
func metaListWithCursor(db *meta.DB, count uint32, cursor *meta.Cursor) ([]object.AddressWithType, *meta.Cursor, error) { func metaListWithCursor(db *meta.DB, count uint32, cursor *meta.Cursor) ([]object.AddressWithType, *meta.Cursor, error) {
var listPrm meta.ListPrm var listPrm meta.ListPrm
listPrm.SetCount(count) listPrm.SetCount(count)