Skip to content

Commit

Permalink
Check redisFormatCommand error result in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiderkwast committed Jan 23, 2023
1 parent 62ead90 commit e4ee3be
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions tests/ut_parse_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ void test_redis_parse_error_nonresp(void) {

void test_redis_parse_cmd_get(void) {
struct cmd *c = command_get();
c->clen = redisFormatCommand(&c->cmd, "GET foo");
int len = redisFormatCommand(&c->cmd, "GET foo");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
ASSERT_KEYS(c, "foo");
Expand All @@ -63,7 +65,9 @@ void test_redis_parse_cmd_get(void) {

void test_redis_parse_cmd_mset(void) {
struct cmd *c = command_get();
c->clen = redisFormatCommand(&c->cmd, "MSET foo val1 bar val2");
int len = redisFormatCommand(&c->cmd, "MSET foo val1 bar val2");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
ASSERT_KEYS(c, "foo", "bar");
Expand All @@ -72,7 +76,9 @@ void test_redis_parse_cmd_mset(void) {

void test_redis_parse_cmd_eval_1(void) {
struct cmd *c = command_get();
c->clen = redisFormatCommand(&c->cmd, "EVAL dummyscript 1 foo");
int len = redisFormatCommand(&c->cmd, "EVAL dummyscript 1 foo");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
ASSERT_KEYS(c, "foo");
Expand All @@ -81,7 +87,9 @@ void test_redis_parse_cmd_eval_1(void) {

void test_redis_parse_cmd_eval_0(void) {
struct cmd *c = command_get();
c->clen = redisFormatCommand(&c->cmd, "EVAL dummyscript 0 foo");
int len = redisFormatCommand(&c->cmd, "EVAL dummyscript 0 foo");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
ASSERT_MSG(hiarray_n(c->keys) == 0, "Nonzero number of keys");
Expand All @@ -90,7 +98,9 @@ void test_redis_parse_cmd_eval_0(void) {

void test_redis_parse_cmd_xgroup_no_subcommand(void) {
struct cmd *c = command_get();
c->clen = redisFormatCommand(&c->cmd, "XGROUP");
int len = redisFormatCommand(&c->cmd, "XGROUP");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_MSG(c->result == CMD_PARSE_ERROR, "Unexpected parse success");
ASSERT_MSG(!strcmp(c->errstr, "Unknown command XGROUP"), c->errstr);
Expand All @@ -99,7 +109,9 @@ void test_redis_parse_cmd_xgroup_no_subcommand(void) {

void test_redis_parse_cmd_xgroup_destroy_no_key(void) {
struct cmd *c = command_get();
c->clen = redisFormatCommand(&c->cmd, "xgroup destroy");
int len = redisFormatCommand(&c->cmd, "xgroup destroy");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_MSG(c->result == CMD_PARSE_ERROR, "Parse not OK");
const char *expected_error =
Expand All @@ -111,7 +123,9 @@ void test_redis_parse_cmd_xgroup_destroy_no_key(void) {

void test_redis_parse_cmd_xgroup_destroy_ok(void) {
struct cmd *c = command_get();
c->clen = redisFormatCommand(&c->cmd, "xgroup destroy mystream mygroup");
int len = redisFormatCommand(&c->cmd, "xgroup destroy mystream mygroup");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_KEYS(c, "mystream");
command_destroy(c);
Expand Down

0 comments on commit e4ee3be

Please sign in to comment.