mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-12 19:30:35 +08:00
Added wrong args tests for RENAME command.
This commit is contained in:
@@ -583,7 +583,7 @@ func handleDecrBy(params internal.HandlerFuncParams) ([]byte, error) {
|
|||||||
|
|
||||||
func handleRename(params internal.HandlerFuncParams) ([]byte, error) {
|
func handleRename(params internal.HandlerFuncParams) ([]byte, error) {
|
||||||
if len(params.Command) != 3 {
|
if len(params.Command) != 3 {
|
||||||
return nil, errors.New("wrong number of arguments for RENAME")
|
return nil, errors.New(constants.WrongArgsResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
oldKey := params.Command[1]
|
oldKey := params.Command[1]
|
||||||
@@ -827,10 +827,11 @@ If the key's value is not of the correct type or cannot be represented as an int
|
|||||||
HandlerFunc: handleDecrBy,
|
HandlerFunc: handleDecrBy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Command: "rename",
|
Command: "rename",
|
||||||
Module: constants.GenericModule,
|
Module: constants.GenericModule,
|
||||||
Categories: []string{constants.KeyspaceCategory, constants.WriteCategory, constants.FastCategory},
|
Categories: []string{constants.KeyspaceCategory, constants.WriteCategory, constants.FastCategory},
|
||||||
Description: `(RENAME key newkey) Renames key to newkey. If newkey already exists, it is overwritten. If key does not exist, an error is returned.`,
|
Description: `(RENAME key newkey)
|
||||||
|
Renames key to newkey. If newkey already exists, it is overwritten. If key does not exist, an error is returned.`,
|
||||||
Sync: true,
|
Sync: true,
|
||||||
KeyExtractionFunc: renameKeyFunc,
|
KeyExtractionFunc: renameKeyFunc,
|
||||||
HandlerFunc: handleRename,
|
HandlerFunc: handleRename,
|
||||||
|
@@ -2442,6 +2442,21 @@ func Test_Generic(t *testing.T) {
|
|||||||
expectedResponse: "OK",
|
expectedResponse: "OK",
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "4. Command too short",
|
||||||
|
command: []resp.Value{resp.StringValue("RENAME"), resp.StringValue("key")},
|
||||||
|
expectedError: errors.New(constants.WrongArgsResponse),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "5. Command too long",
|
||||||
|
command: []resp.Value{
|
||||||
|
resp.StringValue("RENAME"),
|
||||||
|
resp.StringValue("key"),
|
||||||
|
resp.StringValue("newkey"),
|
||||||
|
resp.StringValue("extra_arg"),
|
||||||
|
},
|
||||||
|
expectedError: errors.New(constants.WrongArgsResponse),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Reference in New Issue
Block a user