Skip to content

Commit 92ec828

Browse files
committed
Refine the test
1 parent 73e9680 commit 92ec828

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

test/test_resp_reader.c

+16-13
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66
#define STR_AND_SIZE(str) str, (sizeof(str)-1)
77

8-
const char *ignoreThisRespErr = "ERR Oopsie Daisy!";
9-
int onRespErrorCb(void *callerCtx, char *msg) {
10-
UNUSED(callerCtx);
11-
return (strcmp(msg, ignoreThisRespErr)==0) ? 0 /*mask*/ : 1 /*propagate*/;
12-
}
13-
148
static void test_resp_reader_common(RespReaderCtx *ctx,
159
char *payload,
1610
int payloadSize,
@@ -20,10 +14,7 @@ static void test_resp_reader_common(RespReaderCtx *ctx,
2014
{
2115
RespReaderCtx alterCtx;
2216
if (!ctx) ctx = &alterCtx;
23-
if (initCtx) {
24-
readRespInit(ctx);
25-
setErrorCb(ctx, NULL, onRespErrorCb);
26-
}
17+
if (initCtx) readRespInit(ctx);
2718

2819
RespRes res = readRespReplies(ctx, payload, payloadSize);
2920
assert_int_equal(res, expRes);
@@ -172,11 +163,23 @@ static void test_reply_array_misc_data_types (void **state) {
172163
}
173164

174165
/* Masked error should be counted as valid response */
166+
const char *ignoreThisRespErr = "ERR Oopsie Daisy!";
167+
int onRespErrorCb(void *callerCtx, char *msg) {
168+
UNUSED(callerCtx);
169+
return (strcmp(msg, ignoreThisRespErr)==0) ? 0 /*mask*/ : 1 /*propagate*/;
170+
}
175171
static void test_masked_errors (void **state) {
176172
UNUSED(state);
177-
/* The function test_resp_reader_common mask "-ERR Oopsie Daisy!" */
178-
test_resp_reader_common(NULL, STR_AND_SIZE("$5\r\nmylib\r\n$4\r\nm\rib\r\n-ERR Oopsie Daisy!\r\n$8\r\nm123ylib\r\n"),
179-
1, RESP_REPLY_OK, 4);
173+
/* Ignore "ERR Oopsie Daisy" */
174+
char *payload = "$5\r\nmylib\r\n$4\r\nm\rib\r\n-ERR Oopsie Daisy!\r\n$8\r\n"
175+
"m123ylib\r\n-ERR reported error\r\n-ERR never reached\r\n";
176+
RespReaderCtx ctx;
177+
readRespInit(&ctx);
178+
setErrorCb(&ctx, NULL, onRespErrorCb);
179+
RespRes res = readRespReplies(&ctx, payload, strlen(payload));
180+
assert_int_equal(res, RESP_REPLY_ERR);
181+
assert_int_equal(ctx.countReplies, 4);
182+
assert_string_equal(ctx.errorMsg, "ERR reported error");
180183
}
181184

182185
/*************************** group_test_resp_reader *******************************/

0 commit comments

Comments
 (0)