From 2c4b50a71ed9eaf23a34fe0c327249fc60391cf7 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 10 Apr 2024 14:15:57 +0300 Subject: [PATCH] Reapply "[#972] Use require.ElementsMatch() where possible" This reverts commit 7627d08914ab4cfa6fd73f17e586f4b0f1a0bbc1. Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/engine/list_test.go | 12 +----------- .../metabase/containers_test.go | 12 +----------- pkg/local_object_storage/metabase/list_test.go | 14 +------------- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/pkg/local_object_storage/engine/list_test.go b/pkg/local_object_storage/engine/list_test.go index 7bb1ac0fa..4fc9569c7 100644 --- a/pkg/local_object_storage/engine/list_test.go +++ b/pkg/local_object_storage/engine/list_test.go @@ -3,7 +3,6 @@ package engine import ( "context" "path/filepath" - "sort" "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" @@ -18,13 +17,6 @@ import ( "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) { t.Parallel() @@ -98,7 +90,6 @@ func TestListWithCursor(t *testing.T) { require.NoError(t, err) expected = append(expected, object.AddressWithType{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)}) } - expected = sortAddresses(expected) var prm ListWithCursorPrm prm.count = tt.batchSize @@ -113,8 +104,7 @@ func TestListWithCursor(t *testing.T) { prm.cursor = res.Cursor() } - got = sortAddresses(got) - require.Equal(t, expected, got) + require.ElementsMatch(t, expected, got) }) } } diff --git a/pkg/local_object_storage/metabase/containers_test.go b/pkg/local_object_storage/metabase/containers_test.go index a90cd9d97..5d6788d7e 100644 --- a/pkg/local_object_storage/metabase/containers_test.go +++ b/pkg/local_object_storage/metabase/containers_test.go @@ -3,7 +3,6 @@ package meta_test import ( "context" "math/rand" - "sort" "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" @@ -108,18 +107,9 @@ 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()) require.NoError(t, err) - - sort.Slice(got, func(i, j int) bool { - return got[i].EncodeToString() < got[j].EncodeToString() - }) - - require.Equal(t, expected, got) + require.ElementsMatch(t, expected, got) } func TestDB_ContainerSize(t *testing.T) { diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index 25c0e35bd..e1ccb4e06 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -3,7 +3,6 @@ package meta_test import ( "context" "errors" - "sort" "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" @@ -128,8 +127,6 @@ func TestLisObjectsWithCursor(t *testing.T) { 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) { for countPerReq := 1; countPerReq <= total; countPerReq++ { got := make([]object.AddressWithType, 0, total) @@ -151,9 +148,7 @@ func TestLisObjectsWithCursor(t *testing.T) { _, _, err = metaListWithCursor(db, uint32(countPerReq), cursor) require.ErrorIs(t, err, meta.ErrEndOfListing, "count:%d", countPerReq, cursor) - - got = sortAddresses(got) - require.Equal(t, expected, got, "count:%d", countPerReq) + require.ElementsMatch(t, expected, got, "count:%d", countPerReq) } }) @@ -216,13 +211,6 @@ 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) { var listPrm meta.ListPrm listPrm.SetCount(count)