5
5
6
6
#define STR_AND_SIZE (str ) str, (sizeof(str)-1)
7
7
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
-
14
8
static void test_resp_reader_common (RespReaderCtx * ctx ,
15
9
char * payload ,
16
10
int payloadSize ,
@@ -20,10 +14,7 @@ static void test_resp_reader_common(RespReaderCtx *ctx,
20
14
{
21
15
RespReaderCtx alterCtx ;
22
16
if (!ctx ) ctx = & alterCtx ;
23
- if (initCtx ) {
24
- readRespInit (ctx );
25
- setErrorCb (ctx , NULL , onRespErrorCb );
26
- }
17
+ if (initCtx ) readRespInit (ctx );
27
18
28
19
RespRes res = readRespReplies (ctx , payload , payloadSize );
29
20
assert_int_equal (res , expRes );
@@ -172,11 +163,23 @@ static void test_reply_array_misc_data_types (void **state) {
172
163
}
173
164
174
165
/* 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
+ }
175
171
static void test_masked_errors (void * * state ) {
176
172
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" );
180
183
}
181
184
182
185
/*************************** group_test_resp_reader *******************************/
0 commit comments