diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index c20fbcb43d..b95cfe2698 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -4918,123 +4918,3 @@ func (suite *GlideTestSuite) TestSortStoreWithOptions_ByPattern() { assert.Equal(suite.T(), resultList, sortedValues) }) } - -func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_ExternalWeights() { - suite.SkipIfServerVersionLowerThanBy("8.0.0") - suite.runWithDefaultClients(func(client api.BaseClient) { - if suite.serverVersion < "7.0.0" { - suite.T().Skip("This feature is added in version 7") - } - key := "{listKey}" + uuid.New().String() - client.LPush(key, []string{"item1", "item2", "item3"}) - - client.Set("{weight}_item1", "3") - client.Set("{weight}_item2", "1") - client.Set("{weight}_item3", "2") - - options := options.NewSortOptions(). - SetByPattern("{weight}_*"). - SetOrderBy(options.ASC). - SetIsAlpha(false) - - sortResult, err := client.SortReadOnlyWithOptions(key, options) - - assert.Nil(suite.T(), err) - resultList := []api.Result[string]{ - api.CreateStringResult("item2"), - api.CreateStringResult("item3"), - api.CreateStringResult("item1"), - } - assert.Equal(suite.T(), resultList, sortResult) - }) -} - -func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_GetPatterns() { - suite.SkipIfServerVersionLowerThanBy("8.0.0") - suite.runWithDefaultClients(func(client api.BaseClient) { - if suite.serverVersion < "7.0.0" { - suite.T().Skip("This feature is added in version 7") - } - key := "{listKey}" + uuid.New().String() - client.LPush(key, []string{"item1", "item2", "item3"}) - - client.Set("{object}_item1", "Object_1") - client.Set("{object}_item2", "Object_2") - client.Set("{object}_item3", "Object_3") - - options := options.NewSortOptions(). - SetByPattern("{weight}_*"). - SetOrderBy(options.ASC). - SetIsAlpha(false). - AddGetPattern("{object}_*") - - sortResult, err := client.SortReadOnlyWithOptions(key, options) - - assert.Nil(suite.T(), err) - - resultList := []api.Result[string]{ - api.CreateStringResult("Object_2"), - api.CreateStringResult("Object_3"), - api.CreateStringResult("Object_1"), - } - - assert.Equal(suite.T(), resultList, sortResult) - }) -} - -func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_SuccessfulSortByWeightAndGet() { - suite.SkipIfServerVersionLowerThanBy("8.0.0") - suite.runWithDefaultClients(func(client api.BaseClient) { - if suite.serverVersion < "7.0.0" { - suite.T().Skip("This feature is added in version 7") - } - key := "{listKey}" + uuid.New().String() - client.LPush(key, []string{"item1", "item2", "item3"}) - - client.Set("{weight}_item1", "10") - client.Set("{weight}_item2", "5") - client.Set("{weight}_item3", "15") - - client.Set("{object}_item1", "Object 1") - client.Set("{object}_item2", "Object 2") - client.Set("{object}_item3", "Object 3") - - options := options.NewSortOptions(). - SetOrderBy(options.ASC). - SetIsAlpha(false). - SetByPattern("{weight}_*"). - AddGetPattern("{object}_*"). - AddGetPattern("#") - - sortResult, err := client.SortReadOnlyWithOptions(key, options) - - assert.Nil(suite.T(), err) - - resultList := []api.Result[string]{ - api.CreateStringResult("Object 2"), - api.CreateStringResult("item2"), - api.CreateStringResult("Object 1"), - api.CreateStringResult("item1"), - api.CreateStringResult("Object 3"), - api.CreateStringResult("item3"), - } - - assert.Equal(suite.T(), resultList, sortResult) - - objectItem2, err := client.Get("{object}_item2") - assert.Nil(suite.T(), err) - assert.Equal(suite.T(), "Object 2", objectItem2.Value()) - - objectItem1, err := client.Get("{object}_item1") - assert.Nil(suite.T(), err) - assert.Equal(suite.T(), "Object 1", objectItem1.Value()) - - objectItem3, err := client.Get("{object}_item3") - assert.Nil(suite.T(), err) - assert.Equal(suite.T(), "Object 3", objectItem3.Value()) - - assert.Equal(suite.T(), "item2", sortResult[1].Value()) - assert.Equal(suite.T(), "item1", sortResult[3].Value()) - assert.Equal(suite.T(), "item3", sortResult[5].Value()) - }) -} diff --git a/go/integTest/standalone_commands_test.go b/go/integTest/standalone_commands_test.go index 26cd0d5077..3769bd53a4 100644 --- a/go/integTest/standalone_commands_test.go +++ b/go/integTest/standalone_commands_test.go @@ -8,6 +8,7 @@ import ( "github.com/google/uuid" "github.com/valkey-io/valkey-glide/go/glide/api" + "github.com/valkey-io/valkey-glide/go/glide/api/options" "github.com/stretchr/testify/assert" ) @@ -282,3 +283,117 @@ func (suite *GlideTestSuite) TestSelect_SwitchBetweenDatabases() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), value2, result.Value()) } + +func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_ExternalWeights() { + client := suite.defaultClient() + if suite.serverVersion < "7.0.0" { + suite.T().Skip("This feature is added in version 7") + } + key := uuid.New().String() + client.LPush(key, []string{"item1", "item2", "item3"}) + + client.Set("weight_item1", "3") + client.Set("weight_item2", "1") + client.Set("weight_item3", "2") + + options := options.NewSortOptions(). + SetByPattern("weight_*"). + SetOrderBy(options.ASC). + SetIsAlpha(false) + + sortResult, err := client.SortReadOnlyWithOptions(key, options) + + assert.Nil(suite.T(), err) + resultList := []api.Result[string]{ + api.CreateStringResult("item2"), + api.CreateStringResult("item3"), + api.CreateStringResult("item1"), + } + assert.Equal(suite.T(), resultList, sortResult) +} + +func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_GetPatterns() { + client := suite.defaultClient() + if suite.serverVersion < "7.0.0" { + suite.T().Skip("This feature is added in version 7") + } + key := uuid.New().String() + client.LPush(key, []string{"item1", "item2", "item3"}) + + client.Set("object_item1", "Object_1") + client.Set("object_item2", "Object_2") + client.Set("object_item3", "Object_3") + + options := options.NewSortOptions(). + SetByPattern("weight_*"). + SetOrderBy(options.ASC). + SetIsAlpha(false). + AddGetPattern("object_*") + + sortResult, err := client.SortReadOnlyWithOptions(key, options) + + assert.Nil(suite.T(), err) + + resultList := []api.Result[string]{ + api.CreateStringResult("Object_2"), + api.CreateStringResult("Object_3"), + api.CreateStringResult("Object_1"), + } + + assert.Equal(suite.T(), resultList, sortResult) +} + +func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_SuccessfulSortByWeightAndGet() { + client := suite.defaultClient() + if suite.serverVersion < "7.0.0" { + suite.T().Skip("This feature is added in version 7") + } + key := uuid.New().String() + client.LPush(key, []string{"item1", "item2", "item3"}) + + client.Set("weight_item1", "10") + client.Set("weight_item2", "5") + client.Set("weight_item3", "15") + + client.Set("object_item1", "Object 1") + client.Set("object_item2", "Object 2") + client.Set("object_item3", "Object 3") + + options := options.NewSortOptions(). + SetOrderBy(options.ASC). + SetIsAlpha(false). + SetByPattern("weight_*"). + AddGetPattern("object_*"). + AddGetPattern("#") + + sortResult, err := client.SortReadOnlyWithOptions(key, options) + + assert.Nil(suite.T(), err) + + resultList := []api.Result[string]{ + api.CreateStringResult("Object 2"), + api.CreateStringResult("item2"), + api.CreateStringResult("Object 1"), + api.CreateStringResult("item1"), + api.CreateStringResult("Object 3"), + api.CreateStringResult("item3"), + } + + assert.Equal(suite.T(), resultList, sortResult) + + objectItem2, err := client.Get("object_item2") + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), "Object 2", objectItem2.Value()) + + objectItem1, err := client.Get("object_item1") + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), "Object 1", objectItem1.Value()) + + objectItem3, err := client.Get("object_item3") + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), "Object 3", objectItem3.Value()) + + assert.Equal(suite.T(), "item2", sortResult[1].Value()) + assert.Equal(suite.T(), "item1", sortResult[3].Value()) + assert.Equal(suite.T(), "item3", sortResult[5].Value()) +}