Added wrong args tests for RENAME command.

This commit is contained in:
Kelvin Mwinuka
2024-06-25 22:39:46 +08:00
parent 26959200ed
commit 9b897b472f
2 changed files with 21 additions and 5 deletions

View File

@@ -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,

View File

@@ -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 {