diff options
author | Oran Agra <oran@redislabs.com> | 2019-07-24 12:58:15 +0300 |
---|---|---|
committer | Oran Agra <oran@redislabs.com> | 2019-07-24 12:58:15 +0300 |
commit | e91d9a6fffcac20adfb4fdf2d8fb365ec0816261 (patch) | |
tree | 110062bb352c4df59c893185b65a17132ec479fc /tests | |
parent | bc5cb168f504c188c7e67ca61853fd73c341fa62 (diff) | |
download | redis-e91d9a6fffcac20adfb4fdf2d8fb365ec0816261.tar.gz |
Extend modules API to allow modules report to redis INFO
this implements #6012
Diffstat (limited to 'tests')
-rw-r--r-- | tests/modules/Makefile | 7 | ||||
-rw-r--r-- | tests/modules/infotest.c | 32 | ||||
-rw-r--r-- | tests/unit/moduleapi/infotest.tcl | 53 |
3 files changed, 91 insertions, 1 deletions
diff --git a/tests/modules/Makefile b/tests/modules/Makefile index 014d20afa..66bf6de35 100644 --- a/tests/modules/Makefile +++ b/tests/modules/Makefile @@ -13,12 +13,17 @@ endif .SUFFIXES: .c .so .xo .o -all: commandfilter.so +all: commandfilter.so infotest.so .c.xo: $(CC) -I../../src $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@ commandfilter.xo: ../../src/redismodule.h +infotest.xo: ../../src/redismodule.h commandfilter.so: commandfilter.xo $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc + +infotest.so: infotest.xo + $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc + diff --git a/tests/modules/infotest.c b/tests/modules/infotest.c new file mode 100644 index 000000000..d53ea2126 --- /dev/null +++ b/tests/modules/infotest.c @@ -0,0 +1,32 @@ +#include "redismodule.h" + +#include <string.h> + +void InfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) { + RedisModule_AddInfoSection(ctx, "Spanish"); + RedisModule_AddInfoFieldCString(ctx, "uno", "one"); + RedisModule_AddInfoFieldLongLong(ctx, "dos", 2); + + RedisModule_AddInfoSection(ctx, "Italian"); + RedisModule_AddInfoFieldLongLong(ctx, "due", 2); + RedisModule_AddInfoFieldDouble(ctx, "tre", 3.3); + + if (for_crash_report) { + RedisModule_AddInfoSection(ctx, "Klingon"); + RedisModule_AddInfoFieldCString(ctx, "one", "wa’"); + RedisModule_AddInfoFieldCString(ctx, "two", "cha’"); + RedisModule_AddInfoFieldCString(ctx, "three", "wej"); + } + +} + +int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + REDISMODULE_NOT_USED(argv); + REDISMODULE_NOT_USED(argc); + if (RedisModule_Init(ctx,"infotest",1,REDISMODULE_APIVER_1) + == REDISMODULE_ERR) return REDISMODULE_ERR; + + if (RedisModule_RegisterInfoFunc(ctx, InfoFunc) == REDISMODULE_ERR) return REDISMODULE_ERR; + + return REDISMODULE_OK; +} diff --git a/tests/unit/moduleapi/infotest.tcl b/tests/unit/moduleapi/infotest.tcl new file mode 100644 index 000000000..143f9050a --- /dev/null +++ b/tests/unit/moduleapi/infotest.tcl @@ -0,0 +1,53 @@ +set testmodule [file normalize tests/modules/infotest.so] + +# Return value for INFO property +proc field {info property} { + if {[regexp "\r\n$property:(.*?)\r\n" $info _ value]} { + set _ $value + } +} + +start_server {tags {"modules"}} { + r module load $testmodule log-key 0 + + test {module info all} { + set info [r info all] + # info all does not contain modules + assert { ![string match "*Spanish*" $info] } + assert { [string match "*used_memory*" $info] } + } + + test {module info everything} { + set info [r info everything] + # info everything contains all default sections, but not ones for crash report + assert { [string match "*Spanish*" $info] } + assert { [string match "*Italian*" $info] } + assert { [string match "*used_memory*" $info] } + assert { ![string match "*Klingon*" $info] } + field $info infotest_dos + } {2} + + test {module info modules} { + set info [r info modules] + # info all does not contain modules + assert { [string match "*Spanish*" $info] } + assert { ![string match "*used_memory*" $info] } + } + + test {module info one module} { + set info [r info INFOTEST] + # info all does not contain modules + assert { [string match "*Spanish*" $info] } + assert { ![string match "*used_memory*" $info] } + } + + test {module info one section} { + set info [r info INFOTEST_SPANISH] + assert { ![string match "*used_memory*" $info] } + assert { ![string match "*Italian*" $info] } + field $info infotest_uno + } {one} + + # TODO: test crash report. + +} |