mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-31 03:16:26 +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) {
|
||||
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]
|
||||
@@ -827,10 +827,11 @@ If the key's value is not of the correct type or cannot be represented as an int
|
||||
HandlerFunc: handleDecrBy,
|
||||
},
|
||||
{
|
||||
Command: "rename",
|
||||
Module: constants.GenericModule,
|
||||
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.`,
|
||||
Command: "rename",
|
||||
Module: constants.GenericModule,
|
||||
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.`,
|
||||
Sync: true,
|
||||
KeyExtractionFunc: renameKeyFunc,
|
||||
HandlerFunc: handleRename,
|
||||
|
||||
@@ -2442,6 +2442,21 @@ func Test_Generic(t *testing.T) {
|
||||
expectedResponse: "OK",
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user