diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/modules/reply.c | 10 | ||||
-rw-r--r-- | tests/unit/moduleapi/reply.tcl | 11 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/modules/reply.c b/tests/modules/reply.c index f890560e0..c5baa6635 100644 --- a/tests/modules/reply.c +++ b/tests/modules/reply.c @@ -156,6 +156,14 @@ int rw_error(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { return RedisModule_ReplyWithError(ctx, "An error"); } +int rw_error_format(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + if (argc != 3) return RedisModule_WrongArity(ctx); + + return RedisModule_ReplyWithErrorFormat(ctx, + RedisModule_StringPtrLen(argv[1], NULL), + RedisModule_StringPtrLen(argv[2], NULL)); +} + int rw_verbatim(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (argc != 2) return RedisModule_WrongArity(ctx); @@ -197,6 +205,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"rw.error",rw_error,"",0,0,0) != REDISMODULE_OK) return REDISMODULE_ERR; + if (RedisModule_CreateCommand(ctx,"rw.error_format",rw_error_format,"",0,0,0) != REDISMODULE_OK) + return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"rw.verbatim",rw_verbatim,"",0,0,0) != REDISMODULE_OK) return REDISMODULE_ERR; diff --git a/tests/unit/moduleapi/reply.tcl b/tests/unit/moduleapi/reply.tcl index 291253d3c..547be21c0 100644 --- a/tests/unit/moduleapi/reply.tcl +++ b/tests/unit/moduleapi/reply.tcl @@ -126,6 +126,17 @@ start_server {tags {"modules"}} { assert_match "An error" $e } + test "RESP$proto: RM_ReplyWithErrorFormat: error format reply" { + catch {r rw.error_format "An error: %s" foo} e + assert_match "ERR An error: foo" $e + + catch {r rw.error_format "-ERR An error: %s" foo2} e + assert_match "ERR An error: foo2" $e + + catch {r rw.error_format "-WRONGTYPE A type error: %s" foo3} e + assert_match "WRONGTYPE A type error: foo3" $e + } + r hello 2 } |