summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorViktor Söderqvist <viktor.soderqvist@est.tech>2022-06-27 07:29:05 +0200
committerGitHub <noreply@github.com>2022-06-27 08:29:05 +0300
commit6af021007a70f42e41f2a8abda3719d68b15ada4 (patch)
treeba43ef9d78b19768e20d00af3916a3f291df34fd /tests/modules
parent2854637385f6f44661ebd8833d852c068039e641 (diff)
downloadredis-6af021007a70f42e41f2a8abda3719d68b15ada4.tar.gz
Add missing REDISMODULE_CLIENTINFO_INITIALIZER (#10885)
The module API docs mentions this macro, but it was not defined (so no one could have used it). Instead of adding it as is, we decided to add a _V1 macro, so that if / when we some day extend this struct, modules that use this API and don't need the extra fields, will still use the old version and still be compatible with older redis version (despite being compiled with newer redismodule.h)
Diffstat (limited to 'tests/modules')
-rw-r--r--tests/modules/misc.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/modules/misc.c b/tests/modules/misc.c
index c9ebcc5f9..64b456904 100644
--- a/tests/modules/misc.c
+++ b/tests/modules/misc.c
@@ -240,9 +240,17 @@ int test_clientinfo(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
(void) argv;
(void) argc;
- RedisModuleClientInfo ci = { .version = REDISMODULE_CLIENTINFO_VERSION };
+ RedisModuleClientInfoV1 ci = REDISMODULE_CLIENTINFO_INITIALIZER_V1;
+ uint64_t client_id = RedisModule_GetClientId(ctx);
- if (RedisModule_GetClientInfoById(&ci, RedisModule_GetClientId(ctx)) == REDISMODULE_ERR) {
+ /* Check expected result from the V1 initializer. */
+ assert(ci.version == 1);
+ /* Trying to populate a future version of the struct should fail. */
+ ci.version = REDISMODULE_CLIENTINFO_VERSION + 1;
+ assert(RedisModule_GetClientInfoById(&ci, client_id) == REDISMODULE_ERR);
+
+ ci.version = 1;
+ if (RedisModule_GetClientInfoById(&ci, client_id) == REDISMODULE_ERR) {
RedisModule_ReplyWithError(ctx, "failed to get client info");
return REDISMODULE_OK;
}