redict/tests/unit/moduleapi/getkeys.tcl
Binbin 23325c135f
sub-command support for ACL CAT and COMMAND LIST. redisCommand always stores fullname (#10127)
Summary of changes:
1. Rename `redisCommand->name` to `redisCommand->declared_name`, it is a
  const char * for native commands and SDS for module commands.
2. Store the [sub]command fullname in `redisCommand->fullname` (sds).
3. List subcommands in `ACL CAT`
4. List subcommands in `COMMAND LIST`
5. `moduleUnregisterCommands` now will also free the module subcommands.
6. RM_GetCurrentCommandName returns full command name

Other changes:
1. Add `addReplyErrorArity` and `addReplyErrorExpireTime`
2. Remove `getFullCommandName` function that now is useless.
3. Some cleanups about `fullname` since now it is SDS.
4. Delete `populateSingleCommand` function from server.h that is useless.
5. Added tests to cover this change.
6. Add some module unload tests and fix the leaks
7. Make error messages uniform, make sure they always contain the full command
  name and that it's quoted.
7. Fixes some typos

see the history in #9504, fixes #10124

Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: guybe7 <guy.benoish@redislabs.com>
2022-01-23 10:05:06 +02:00

49 lines
1.6 KiB
Tcl

set testmodule [file normalize tests/modules/getkeys.so]
start_server {tags {"modules"}} {
r module load $testmodule
test {COMMAND INFO correctly reports a movable keys module command} {
set info [lindex [r command info getkeys.command] 0]
assert_equal {module movablekeys} [lindex $info 2]
assert_equal {0} [lindex $info 3]
assert_equal {0} [lindex $info 4]
assert_equal {0} [lindex $info 5]
}
test {COMMAND GETKEYS correctly reports a movable keys module command} {
r command getkeys getkeys.command arg1 arg2 key key1 arg3 key key2 key key3
} {key1 key2 key3}
test {RM_GetCommandKeys on non-existing command} {
catch {r getkeys.introspect non-command key1 key2} e
set _ $e
} {*ENOENT*}
test {RM_GetCommandKeys on built-in fixed keys command} {
r getkeys.introspect set key1 value1
} {key1}
test {RM_GetCommandKeys on EVAL} {
r getkeys.introspect eval "" 4 key1 key2 key3 key4 arg1 arg2
} {key1 key2 key3 key4}
test {RM_GetCommandKeys on a movable keys module command} {
r getkeys.introspect getkeys.command arg1 arg2 key key1 arg3 key key2 key key3
} {key1 key2 key3}
test {RM_GetCommandKeys on a non-movable module command} {
r getkeys.introspect getkeys.fixed arg1 key1 key2 key3 arg2
} {key1 key2 key3}
test {RM_GetCommandKeys with bad arity} {
catch {r getkeys.introspect set key} e
set _ $e
} {*EINVAL*}
test "Unload the module - getkeys" {
assert_equal {OK} [r module unload getkeys]
}
}