• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proftpd / proftpd / 30135626854

25 Jul 2026 12:15AM UTC coverage: 93.034% (+0.6%) from 92.428%
30135626854

push

github

51363 of 55209 relevant lines covered (93.03%)

219.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.69
/tests/api/redis.c
1
/*
2
 * ProFTPD - FTP server testsuite
3
 * Copyright (c) 2017-2026 The ProFTPD Project team
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
17
 *
18
 * As a special exemption, The ProFTPD Project team and other respective
19
 * copyright holders give permission to link this program with OpenSSL, and
20
 * distribute the resulting executable, without including the source code for
21
 * OpenSSL in the source distribution.
22
 */
23

24
/* Redis API tests. */
25

26
#include "tests.h"
27

28
#if defined(PR_USE_REDIS)
29

30
static pool *p = NULL;
31
static const char *redis_server = "127.0.0.1";
32
static int redis_port = 6379;
33

34
/* Fixtures */
35

36
static void set_up(void) {
37
  const char *key, *val;
68✔
38

68✔
39
  if (p == NULL) {
40
    p = permanent_pool = make_sub_pool(NULL);
68✔
41
  }
68✔
42

43
  redis_init();
44

68✔
45
  key = "REDIS_HOST";
46
  val = getenv(key);
68✔
47
  if (val != NULL) {
68✔
48
    redis_server = val;
68✔
49
  }
68✔
50

51
  key = "REDIS_PORT";
52
  val = getenv(key);
68✔
53
  if (val != NULL) {
68✔
54
    redis_port = atoi(val);
68✔
55
  }
×
56

57
  redis_set_server(redis_server, redis_port, 0UL, NULL, NULL);
58

68✔
59
  if (getenv("TEST_VERBOSE") != NULL) {
60
    pr_trace_set_levels("redis", 1, 20);
68✔
61
  }
68✔
62
}
63

68✔
64
static void tear_down(void) {
65
  if (getenv("TEST_VERBOSE") != NULL) {
68✔
66
    pr_trace_set_levels("redis", 0, 0);
68✔
67
  }
68✔
68

69
  redis_clear();
70

68✔
71
  if (p) {
72
    destroy_pool(p);
68✔
73
    p = permanent_pool = NULL;
68✔
74
  }
68✔
75
}
76

68✔
77
/* Tests */
78

79
START_TEST (redis_conn_destroy_test) {
80
  int res;
1✔
81

1✔
82
  mark_point();
83
  res = pr_redis_conn_destroy(NULL);
1✔
84
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
85
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
86
    strerror(errno), errno);
1✔
87
}
88
END_TEST
1✔
89

90
START_TEST (redis_conn_close_test) {
91
  int res;
1✔
92

1✔
93
  mark_point();
94
  res = pr_redis_conn_close(NULL);
1✔
95
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
96
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
97
    strerror(errno), errno);
1✔
98
}
99
END_TEST
1✔
100

101
START_TEST (redis_conn_new_test) {
102
  int res;
1✔
103
  pr_redis_t *redis;
1✔
104

1✔
105
  mark_point();
106
  redis = pr_redis_conn_new(NULL, NULL, 0);
1✔
107
  ck_assert_msg(redis == NULL, "Failed to handle null pool");
1✔
108
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
109
    strerror(errno), errno);
1✔
110

111
  mark_point();
112
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
113
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
114
    strerror(errno));
1✔
115

116
  mark_point();
117
  res = pr_redis_conn_destroy(redis);
1✔
118
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
119

1✔
120
  if (getenv("CI") == NULL) {
121
    /* Now deliberately set the wrong server and port. */
1✔
122
    redis_set_server("127.1.2.3", redis_port, 0UL, NULL, NULL);
123

×
124
    mark_point();
125
    redis = pr_redis_conn_new(p, NULL, 0);
×
126
    ck_assert_msg(redis == NULL, "Failed to handle invalid address");
×
127
    ck_assert_msg(errno == EIO, "Expected EIO (%d), got %s (%d)", EIO,
×
128
      strerror(errno), errno);
×
129
  }
130

131
  redis_set_server(redis_server, 1020, 0UL, NULL, NULL);
132

1✔
133
  mark_point();
134
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
135
  ck_assert_msg(redis == NULL, "Failed to handle invalid port");
1✔
136
  ck_assert_msg(errno == EIO, "Expected EIO (%d), got %s (%d)", EIO,
1✔
137
    strerror(errno), errno);
1✔
138

139
  /* Deliberately use a nonexistent path for the Unix socket use case. */
140
  redis_set_server("/path/to/redis", redis_port, 0UL, NULL, NULL);
141
  mark_point();
1✔
142
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
143
  ck_assert_msg(redis == NULL, "Failed to handle invalid Unix socket path");
144
  ck_assert_msg(errno == EIO, "Expected EIO (%d), got %s (%d)", EIO,
145
    strerror(errno), errno);
1✔
146

1✔
147
  /* Restore our testing server/port. */
1✔
148
  redis_set_server(redis_server, redis_port, 0UL, NULL, NULL);
149
}
1✔
150
END_TEST
1✔
151

1✔
152
START_TEST (redis_conn_get_test) {
1✔
153
  int res;
154
  pr_redis_t *redis, *redis2;
155

1✔
156
  mark_point();
1✔
157
  redis = pr_redis_conn_get(NULL, 0UL);
1✔
158
  ck_assert_msg(redis == NULL, "Failed to handle null pool");
159
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
160
    strerror(errno), errno);
1✔
161

1✔
162
  mark_point();
1✔
163
  redis = pr_redis_conn_get(p, 0UL);
164
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
165
    strerror(errno));
1✔
166

1✔
167
  mark_point();
168
  res = pr_redis_conn_destroy(redis);
169
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
170

1✔
171
  mark_point();
1✔
172
  redis = pr_redis_conn_get(p, 0UL);
173
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
174
    strerror(errno));
175

1✔
176
  mark_point();
1✔
177
  redis2 = pr_redis_conn_get(p, 0UL);
1✔
178
  ck_assert_msg(redis2 != NULL, "Failed to open connection to Redis: %s",
179
    strerror(errno));
1✔
180
  ck_assert_msg(redis == redis2, "Expected %p, got %p", redis, redis2);
1✔
181

1✔
182
  mark_point();
1✔
183
  res = pr_redis_conn_destroy(redis);
184
  ck_assert_msg(res == FALSE, "Expected FALSE, got TRUE");
185

1✔
186
  mark_point();
1✔
187
  res = pr_redis_conn_destroy(redis);
1✔
188
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
189
}
1✔
190
END_TEST
1✔
191

192
START_TEST (redis_conn_set_namespace_test) {
1✔
193
  int res;
1✔
194
  pr_redis_t *redis;
1✔
195
  module m;
1✔
196
  const char *prefix;
197
  size_t prefixsz;
198

1✔
199
  mark_point();
1✔
200
  res = pr_redis_conn_set_namespace(NULL, NULL, NULL, 0);
1✔
201
  ck_assert_msg(res < 0, "Failed to handle null redis");
202
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
203
    strerror(errno), errno);
1✔
204

1✔
205
  mark_point();
1✔
206
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
207
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
208
    strerror(errno));
209

1✔
210
  mark_point();
1✔
211
  res = pr_redis_conn_set_namespace(redis, NULL, NULL, 0);
1✔
212
  ck_assert_msg(res < 0, "Failed to handle null module");
213
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
214
    strerror(errno), errno);
1✔
215

1✔
216
  mark_point();
217
  res = pr_redis_conn_set_namespace(redis, &m, NULL, 0);
1✔
218
  ck_assert_msg(res == 0, "Failed to set null namespace prefix: %s",
1✔
219
    strerror(errno));
1✔
220

1✔
221
  prefix = "test.";
222
  prefixsz = strlen(prefix);
223

1✔
224
  mark_point();
1✔
225
  res = pr_redis_conn_set_namespace(redis, &m, prefix, 0);
1✔
226
  ck_assert_msg(res < 0, "Failed to handle empty namespace prefix");
227
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
228
    strerror(errno), errno);
1✔
229

1✔
230
  mark_point();
1✔
231
  res = pr_redis_conn_set_namespace(redis, &m, prefix, prefixsz);
232
  ck_assert_msg(res == 0, "Failed to set namespace prefix '%s': %s", prefix,
233
    strerror(errno));
1✔
234

1✔
235
  mark_point();
1✔
236
  res = pr_redis_conn_set_namespace(redis, &m, NULL, 0);
1✔
237
  ck_assert_msg(res == 0, "Failed to set null namespace prefix: %s",
238
    strerror(errno));
239

1✔
240
  mark_point();
1✔
241
  res = pr_redis_conn_destroy(redis);
1✔
242
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
243
}
244
END_TEST
1✔
245

1✔
246
START_TEST (redis_conn_get_version_test) {
1✔
247
  int res;
1✔
248
  pr_redis_t *redis;
249
  unsigned int major = 0, minor = 0, patch = 0;
250

1✔
251
  mark_point();
1✔
252
  res = pr_redis_conn_get_version(NULL, NULL, NULL, NULL);
1✔
253
  ck_assert_msg(res < 0, "Failed to handle null redis");
254
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
255
    strerror(errno), errno);
1✔
256

1✔
257
  mark_point();
1✔
258
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
259
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
260
    strerror(errno));
261

1✔
262
  mark_point();
1✔
263
  res = pr_redis_conn_get_version(redis, NULL, NULL, NULL);
1✔
264
  ck_assert_msg(res < 0, "Failed to handle null version arguments");
265
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
266
    strerror(errno), errno);
1✔
267

1✔
268
  mark_point();
1✔
269
  res = pr_redis_conn_get_version(redis, &major, &minor, &patch);
270
  ck_assert_msg(res == 0, "Failed to get Redis version: %s", strerror(errno));
271

1✔
272
  mark_point();
1✔
273
  res = pr_redis_conn_destroy(redis);
1✔
274
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
275
}
1✔
276
END_TEST
1✔
277

278
START_TEST (redis_conn_auth_test) {
1✔
279
  int res;
1✔
280
  pr_redis_t *redis;
1✔
281
  const char *text;
1✔
282
  array_header *args;
283
  unsigned int major_version = 0;
284

1✔
285
  mark_point();
1✔
286
  res = pr_redis_auth(NULL, NULL);
1✔
287
  ck_assert_msg(res < 0, "Failed to handle null redis");
288
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
289
    strerror(errno), errno);
1✔
290

1✔
291
  mark_point();
1✔
292
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
293
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
294
    strerror(errno));
295

296
  mark_point();
297
  res = pr_redis_auth(redis, NULL);
298
  ck_assert_msg(res < 0, "Failed to handle null password");
299
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
300
    strerror(errno), errno);
301

302
  /* What happens if we try to AUTH to a non-password-protected Redis?
303
   * Answer: Redis returns an error indicating that no password is required.
1✔
304
   *
1✔
305
   * Note that this behavior changed with Redis 6.x.  In particular, any
1✔
306
   * "AUTH default ..." command automatically succeeds with Redis 6.x,
307
   * regardless of the actual password given.  Sigh.
1✔
308
   */
1✔
309

1✔
310
  mark_point();
311
  res = pr_redis_conn_get_version(redis, &major_version, NULL, NULL);
1✔
312
  ck_assert_msg(res == 0, "Failed to get Redis version: %s", strerror(errno));
×
313

×
314
  mark_point();
315
  text = "password";
316
  res = pr_redis_auth(redis, text);
317

×
318
  if (major_version < 6) {
×
319
    ck_assert_msg(res < 0, "Failed to handle lack of need for authentication");
×
320
    ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
×
321
      strerror(errno), errno);
×
322

323
    /* Use CONFIG SET to require a password. */
×
324
    args = make_array(p, 0, sizeof(char *));
×
325
    *((char **) push_array(args)) = pstrdup(p, "CONFIG");
×
326
    *((char **) push_array(args)) = pstrdup(p, "SET");
327
    *((char **) push_array(args)) = pstrdup(p, "requirepass");
328
    *((char **) push_array(args)) = pstrdup(p, text);
×
329

×
330
    mark_point();
331
    res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_STATUS);
×
332
    ck_assert_msg(res == 0, "Failed to enable authentication: %s",
×
333
      strerror(errno));
×
334

×
335
    args = make_array(p, 0, sizeof(char *));
336
    *((char **) push_array(args)) = pstrdup(p, "TIME");
337

×
338
    mark_point();
×
339
    res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_ARRAY);
×
340
    ck_assert_msg(res < 0, "Failed to handle required authentication");
341
    ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
342
      strerror(errno), errno);
×
343

×
344
    mark_point();
×
345
    res = pr_redis_auth(redis, text);
×
346
    ck_assert_msg(res == 0, "Failed to authenticate client: %s", strerror(errno));
×
347

348
    /* Don't forget to remove the password. */
×
349
    args = make_array(p, 0, sizeof(char *));
×
350
    *((char **) push_array(args)) = pstrdup(p, "CONFIG");
×
351
    *((char **) push_array(args)) = pstrdup(p, "SET");
352
    *((char **) push_array(args)) = pstrdup(p, "requirepass");
353
    *((char **) push_array(args)) = pstrdup(p, "");
354

1✔
355
    mark_point();
356
    res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_STATUS);
357
    ck_assert_msg(res == 0, "Failed to remove password authentication: %s",
358
      strerror(errno));
1✔
359

1✔
360
  } else {
1✔
361
    ck_assert_msg(res == 0, "Failed to handle AUTH command: %s",
1✔
362
      strerror(errno));
363
  }
364

1✔
365
  mark_point();
1✔
366
  res = pr_redis_conn_destroy(redis);
1✔
367
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
368
}
1✔
369
END_TEST
1✔
370

371
START_TEST (redis_conn_auth2_test) {
1✔
372
  int res;
1✔
373
  pr_redis_t *redis;
1✔
374
  const char *username, *password;
1✔
375
  array_header *args;
376
  unsigned int major_version = 0;
377

1✔
378
  mark_point();
1✔
379
  res = pr_redis_auth2(NULL, NULL, NULL);
1✔
380
  ck_assert_msg(res < 0, "Failed to handle null redis");
381
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
382
    strerror(errno), errno);
1✔
383

1✔
384
  mark_point();
1✔
385
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
386
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
387
    strerror(errno));
388

389
  mark_point();
390
  res = pr_redis_auth2(redis, NULL, NULL);
391
  ck_assert_msg(res < 0, "Failed to handle null username");
1✔
392
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
393
    strerror(errno), errno);
1✔
394

1✔
395
  /* Note: Do NOT use "default" as the initial username; that name has
1✔
396
   * specific semantics for Redis 6.x and later.
1✔
397
   */
398
  username = "foobar";
399

400
  mark_point();
401
  res = pr_redis_auth2(redis, username, NULL);
402
  ck_assert_msg(res < 0, "Failed to handle null password");
403
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
404
    strerror(errno), errno);
405

406
  /* What happens if we try to AUTH to a non-password-protected Redis?
407
   * Answer: Redis returns an error indicating that no password is required.
1✔
408
   *
1✔
409
   * Note that this behavior changed with Redis 6.x.  In particular, any
1✔
410
   * "AUTH default ..." command automatically succeeds with Redis 6.x,
411
   * regardless of the actual password given.  Sigh.
1✔
412
   */
1✔
413

1✔
414
  mark_point();
1✔
415
  res = pr_redis_conn_get_version(redis, &major_version, NULL, NULL);
1✔
416
  ck_assert_msg(res == 0, "Failed to get Redis version: %s", strerror(errno));
417

418
  mark_point();
1✔
419
  password = "password";
420
  res = pr_redis_auth2(redis, username, password);
×
421
  ck_assert_msg(res < 0, "Failed to handle lack of need for authentication");
×
422
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
×
423
    strerror(errno), errno);
×
424

×
425
  if (major_version < 6) {
426
    /* Use CONFIG SET to require a password. */
×
427
    args = make_array(p, 0, sizeof(char *));
×
428
    *((char **) push_array(args)) = pstrdup(p, "CONFIG");
×
429
    *((char **) push_array(args)) = pstrdup(p, "SET");
430
    *((char **) push_array(args)) = pstrdup(p, "requirepass");
431
    *((char **) push_array(args)) = pstrdup(p, password);
×
432

×
433
    mark_point();
434
    res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_STATUS);
×
435
    ck_assert_msg(res == 0, "Failed to enable authentication: %s",
×
436
      strerror(errno));
×
437

×
438
    args = make_array(p, 0, sizeof(char *));
439
    *((char **) push_array(args)) = pstrdup(p, "TIME");
440

×
441
    mark_point();
×
442
    res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_ARRAY);
×
443
    ck_assert_msg(res < 0, "Failed to handle required authentication");
444
    ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
445
      strerror(errno), errno);
×
446

×
447
    mark_point();
×
448
    res = pr_redis_auth2(redis, username, password);
×
449
    ck_assert_msg(res == 0, "Failed to authenticate client: %s", strerror(errno));
×
450

451
    /* Don't forget to remove the password. */
×
452
    args = make_array(p, 0, sizeof(char *));
×
453
    *((char **) push_array(args)) = pstrdup(p, "CONFIG");
×
454
    *((char **) push_array(args)) = pstrdup(p, "SET");
455
    *((char **) push_array(args)) = pstrdup(p, "requirepass");
456
    *((char **) push_array(args)) = pstrdup(p, "");
457

1✔
458
    mark_point();
1✔
459
    res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_STATUS);
1✔
460
    ck_assert_msg(res == 0, "Failed to remove password authentication: %s",
1✔
461
      strerror(errno));
462
  }
463

1✔
464
  mark_point();
1✔
465
  res = pr_redis_conn_destroy(redis);
1✔
466
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
467
}
468
END_TEST
1✔
469

1✔
470
START_TEST (redis_conn_select_test) {
1✔
471
  int res;
1✔
472
  pr_redis_t *redis;
473
  const char *text;
474

1✔
475
  mark_point();
1✔
476
  res = pr_redis_select(NULL, NULL);
1✔
477
  ck_assert_msg(res < 0, "Failed to handle null redis");
478
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
479
    strerror(errno), errno);
1✔
480

1✔
481
  mark_point();
1✔
482
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
483
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
484
    strerror(errno));
485

1✔
486
  mark_point();
1✔
487
  res = pr_redis_select(redis, NULL);
1✔
488
  ck_assert_msg(res < 0, "Failed to handle null db_idx");
1✔
489
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
490
    strerror(errno), errno);
491

492
  mark_point();
1✔
493
  text = "-1";
1✔
494
  res = pr_redis_select(redis, text);
1✔
495
  ck_assert_msg(res < 0, "Failed to handle invalid index %s", text);
1✔
496
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
497
    strerror(errno), errno);
498

499
  mark_point();
1✔
500
  text = "100";
1✔
501
  res = pr_redis_select(redis, text);
1✔
502
  ck_assert_msg(res < 0, "Failed to handle invalid index %s", text);
1✔
503
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
504
    strerror(errno), errno);
505

506
  mark_point();
1✔
507
  text = "someotherlabel";
1✔
508
  res = pr_redis_select(redis, text);
1✔
509
  ck_assert_msg(res < 0, "Failed to handle invalid index %s", text);
1✔
510
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
511
    strerror(errno), errno);
512

1✔
513
  mark_point();
1✔
514
  text = "0";
1✔
515
  res = pr_redis_select(redis, text);
1✔
516
  ck_assert_msg(res == 0, "Failed to select database %s: %s", text,
517
    strerror(errno));
518

1✔
519
  mark_point();
1✔
520
  text = "1";
1✔
521
  res = pr_redis_select(redis, text);
1✔
522
  ck_assert_msg(res == 0, "Failed to select database %s: %s", text,
523
    strerror(errno));
524

1✔
525
  mark_point();
1✔
526
  res = pr_redis_conn_destroy(redis);
1✔
527
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
528
}
529
END_TEST
530

531
START_TEST (redis_conn_reconnect_test) {
1✔
532
  int res;
533
  pr_redis_t *redis;
534
  array_header *args;
535

×
536
  /* Note: This test is intended to be run manually, locally. */
×
537

×
538
  if (getenv("REDIS_RECONNECT") == NULL) {
539
    return;
540
  }
541

542
  mark_point();
543
  redis = pr_redis_conn_new(p, NULL, 0);
×
544
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
×
545
    strerror(errno));
×
546

547
  /* Now we PAUSE, and elsewhere, stop/start the Redis server, breaking the
×
548
   * connection.
×
549
   */
550
  pr_trace_msg("redis", 1, "PAUSING test while admin restarts Redis server");
551
  pr_timer_sleep(15);
×
552
  pr_trace_msg("redis", 1, "RESUMING test");
×
553

×
554
  args = make_array(p, 0, sizeof(char *));
×
555
  *((char **) push_array(args)) = pstrdup(p, "INFO");
556

557
  /* This first one should fail, due to the reconnect. */
×
558
  mark_point();
×
559
  res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_STRING);
×
560
  ck_assert_msg(res < 0, "Failed to handle reconnect");
561
  ck_assert_msg(errno == EIO, "Expected EIO (%d), got %s (%d)", EIO,
562
    strerror(errno), errno);
563

×
564
  mark_point();
×
565
  res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_STRING);
×
566
  ck_assert_msg(res == 0, "Failed to handle valid command with array: %s",
567
    strerror(errno));
568

569
  mark_point();
1✔
570
  res = pr_redis_conn_destroy(redis);
1✔
571
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
572
}
1✔
573
END_TEST
574

1✔
575
START_TEST (redis_command_test) {
1✔
576
  int res;
1✔
577
  pr_redis_t *redis;
1✔
578
  array_header *args;
579

580
  mark_point();
1✔
581
  res = pr_redis_command(NULL, NULL, 0);
1✔
582
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
583
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
584
    strerror(errno), errno);
585

1✔
586
  mark_point();
1✔
587
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
588
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
589
    strerror(errno));
590

591
  mark_point();
1✔
592
  res = pr_redis_command(redis, NULL, 0);
593
  ck_assert_msg(res < 0, "Failed to handle null args");
1✔
594
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
595
    strerror(errno), errno);
1✔
596

1✔
597
  args = make_array(p, 0, sizeof(char *));
598

599
  mark_point();
1✔
600
  res = pr_redis_command(redis, args, 0);
601
  ck_assert_msg(res < 0, "Failed to handle empty args");
1✔
602
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
603
    strerror(errno), errno);
1✔
604

1✔
605
  *((char **) push_array(args)) = pstrdup(p, "FOO");
606

607
  mark_point();
1✔
608
  res = pr_redis_command(redis, args, -1);
1✔
609
  ck_assert_msg(res < 0, "Failed to handle invalid reply type");
1✔
610
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
611
    strerror(errno), errno);
612

1✔
613
  mark_point();
1✔
614
  res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_ERROR);
1✔
615
  ck_assert_msg(res == 0, "Failed to handle invalid command with error: %s",
616
    strerror(errno));
1✔
617

1✔
618
  args = make_array(p, 0, sizeof(char *));
1✔
619
  *((char **) push_array(args)) = pstrdup(p, "COMMAND");
620
  *((char **) push_array(args)) = pstrdup(p, "COUNT");
621

1✔
622
  mark_point();
1✔
623
  res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_INTEGER);
624
  ck_assert_msg(res == 0, "Failed to handle valid command with integer: %s",
1✔
625
    strerror(errno));
1✔
626

1✔
627
  args = make_array(p, 0, sizeof(char *));
628
  *((char **) push_array(args)) = pstrdup(p, "INFO");
629

1✔
630
  mark_point();
1✔
631
  res = pr_redis_command(redis, args, PR_REDIS_REPLY_TYPE_STRING);
1✔
632
  ck_assert_msg(res == 0, "Failed to handle valid command with array: %s",
1✔
633
    strerror(errno));
634

635
  mark_point();
1✔
636
  res = pr_redis_conn_destroy(redis);
1✔
637
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
638
}
1✔
639
END_TEST
1✔
640

641
START_TEST (redis_sentinel_get_master_addr_test) {
1✔
642
  int res;
1✔
643
  pr_redis_t *redis;
1✔
644
  pr_netaddr_t *addr = NULL;
1✔
645
  const char *name;
646

647
  mark_point();
1✔
648
  res = pr_redis_sentinel_get_master_addr(NULL, NULL, NULL, NULL);
1✔
649
  ck_assert_msg(res < 0, "Failed to handle null pool");
1✔
650
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
651
    strerror(errno), errno);
652

653
  mark_point();
1✔
654
  res = pr_redis_sentinel_get_master_addr(p, NULL, NULL, NULL);
1✔
655
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
656
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
657
    strerror(errno), errno);
658

1✔
659
  mark_point();
1✔
660
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
661
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
662
    strerror(errno));
663

664
  mark_point();
1✔
665
  res = pr_redis_sentinel_get_master_addr(p, redis, NULL, NULL);
1✔
666
  ck_assert_msg(res < 0, "Failed to handle null name");
1✔
667
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
668
    strerror(errno), errno);
1✔
669

670
  mark_point();
671
  name = "foobar";
1✔
672
  res = pr_redis_sentinel_get_master_addr(p, redis, name, NULL);
1✔
673
  ck_assert_msg(res < 0, "Failed to handle null addr");
1✔
674
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
675
    strerror(errno), errno);
1✔
676

677
  mark_point();
678
  name = "foobar";
1✔
679
  res = pr_redis_sentinel_get_master_addr(p, redis, name, &addr);
1✔
680
  ck_assert_msg(res < 0, "Failed to handle invalid sentinel");
1✔
681
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
682
    strerror(errno), errno);
683

684
  mark_point();
1✔
685
  res = pr_redis_conn_destroy(redis);
1✔
686
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
687
}
1✔
688
END_TEST
689

1✔
690
START_TEST (redis_sentinel_get_masters_test) {
1✔
691
  int res;
1✔
692
  pr_redis_t *redis;
1✔
693
  array_header *masters = NULL;
694

695
  mark_point();
1✔
696
  res = pr_redis_sentinel_get_masters(NULL, NULL, NULL);
1✔
697
  ck_assert_msg(res < 0, "Failed to handle null pool");
1✔
698
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
699
    strerror(errno), errno);
700

701
  mark_point();
1✔
702
  res = pr_redis_sentinel_get_masters(p, NULL, NULL);
1✔
703
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
704
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
705
    strerror(errno), errno);
706

1✔
707
  mark_point();
1✔
708
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
709
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
710
    strerror(errno));
711

712
  mark_point();
1✔
713
  res = pr_redis_sentinel_get_masters(p, redis, NULL);
1✔
714
  ck_assert_msg(res < 0, "Failed to handle null masters");
1✔
715
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
716
    strerror(errno), errno);
717

718
  mark_point();
1✔
719
  res = pr_redis_sentinel_get_masters(p, redis, &masters);
1✔
720
  ck_assert_msg(res < 0, "Failed to handle invalid sentinel");
1✔
721
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
722
    strerror(errno), errno);
723

724
  mark_point();
1✔
725
  res = pr_redis_conn_destroy(redis);
1✔
726
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
727
}
1✔
728
END_TEST
1✔
729

1✔
730
START_TEST (redis_sentinel_conn_new_test) {
731
  int res;
732
  pr_redis_t *redis;
733
  array_header *sentinels = NULL;
734
  const char *master = NULL;
1✔
735
  const pr_netaddr_t *addr;
736

1✔
737
  /* Deliberately set the wrong server and port; we want to discover the
738
   * correct host/port via the Sentinels.
1✔
739
   */
740
  redis_set_server(NULL, -2, 0UL, NULL, NULL);
1✔
741

1✔
742
  sentinels = make_array(p, 0, sizeof(pr_netaddr_t *));
1✔
743

744
  if (getenv("CI") != NULL) {
1✔
745
    /* Treat the local Redis server as a Sentinel. */
1✔
746
    addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
1✔
747
    pr_netaddr_set_port2((pr_netaddr_t *) addr, 6379);
748
    *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
1✔
749

1✔
750
    mark_point();
1✔
751
    res = redis_set_sentinels(sentinels, NULL);
1✔
752
    ck_assert_msg(res == 0, "Failed to set sentinel list: %s", strerror(errno));
753

754
    mark_point();
755
    redis = pr_redis_conn_new(p, NULL, 0);
1✔
756
    ck_assert_msg(redis == NULL, "Failed to handle invalid sentinels");
1✔
757
    ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
758
      strerror(errno), errno);
1✔
759

760
    /* Restore our testing server/port. */
761
    redis_set_server(redis_server, redis_port, 0UL, NULL, NULL);
×
762
    redis_set_sentinels(NULL, NULL);
×
763

×
764
    return;
×
765
  }
766

767
  mark_point();
768
  res = redis_set_sentinels(sentinels, NULL);
×
769
  ck_assert_msg(res < 0, "Failed to handle empty sentinel list");
×
770
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
×
771
    strerror(errno), errno);
772

×
773
  /* Set a list of bad sentinels */
×
774
  addr = pr_netaddr_get_addr(p, "127.1.2.3", NULL);
×
775
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 26379);
776
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
777

×
778
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
×
779
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 16379);
780
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
781

×
782
  mark_point();
×
783
  res = redis_set_sentinels(sentinels, NULL);
×
784
  ck_assert_msg(res == 0, "Failed to set sentinels: %s", strerror(errno));
785

786
  mark_point();
787
  redis = pr_redis_conn_new(p, NULL, 0);
×
788
  ck_assert_msg(redis == NULL, "Failed to handle invalid sentinels");
×
789
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
790
    strerror(errno), errno);
×
791

×
792
  /* Set a list of one bad, one good sentinel -- use "bad" master" */
×
793
  sentinels = make_array(p, 0, sizeof(pr_netaddr_t *));
794
  master = "foobar";
×
795

×
796
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
×
797
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 16379);
798
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
799

×
800
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
×
801
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 26379);
802
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
803

×
804
  mark_point();
×
805
  res = redis_set_sentinels(sentinels, master);
×
806
  ck_assert_msg(res == 0, "Failed to set sentinels: %s", strerror(errno));
807

808
  mark_point();
809
  redis = pr_redis_conn_new(p, NULL, 0);
×
810
  ck_assert_msg(redis == NULL, "Failed to handle invalid master");
×
811
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
812
    strerror(errno), errno);
×
813

×
814
  /* Set a list of one bad, one good sentinel -- use "good" master */
×
815
  sentinels = make_array(p, 0, sizeof(pr_netaddr_t *));
816
  master = "proftpd";
×
817

×
818
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
×
819
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 16379);
820
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
821

×
822
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
×
823
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 26379);
824
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
825

×
826
  mark_point();
×
827
  res = redis_set_sentinels(sentinels, master);
828
  ck_assert_msg(res == 0, "Failed to set sentinels: %s", strerror(errno));
829

×
830
  mark_point();
×
831
  redis = pr_redis_conn_new(p, NULL, 0);
×
832
  ck_assert_msg(redis != NULL, "Failed to discover valid master: %s",
833
    strerror(errno));
834

×
835
  mark_point();
×
836
  res = pr_redis_conn_destroy(redis);
837
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
×
838

×
839
  /* Set a list of one bad, one good sentinel -- use no master */
×
840
  sentinels = make_array(p, 0, sizeof(pr_netaddr_t *));
841
  master = NULL;
×
842

×
843
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
×
844
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 16379);
845
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
846

×
847
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
×
848
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 26379);
849
  *((pr_netaddr_t **) push_array(sentinels)) = (pr_netaddr_t *) addr;
×
850

×
851
  mark_point();
×
852
  res = redis_set_sentinels(sentinels, master);
853
  ck_assert_msg(res == 0, "Failed to set sentinels: %s", strerror(errno));
854

×
855
  mark_point();
×
856
  redis = pr_redis_conn_new(p, NULL, 0);
×
857
  ck_assert_msg(redis != NULL, "Failed to discover valid master: %s",
858
    strerror(errno));
859

×
860
  mark_point();
×
861
  res = pr_redis_conn_destroy(redis);
862
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
863

864
  /* Restore our testing server/port. */
1✔
865
  redis_set_server(redis_server, redis_port, 0UL, NULL, NULL);
1✔
866
  redis_set_sentinels(NULL, NULL);
1✔
867
}
1✔
868
END_TEST
1✔
869

870
START_TEST (redis_remove_test) {
1✔
871
  int res;
1✔
872
  pr_redis_t *redis;
1✔
873
  module m;
1✔
874
  const char *key;
875

876
  mark_point();
1✔
877
  res = pr_redis_remove(NULL, NULL, NULL);
1✔
878
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
879
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
880
    strerror(errno), errno);
881

1✔
882
  mark_point();
1✔
883
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
884
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
885
    strerror(errno));
886

887
  mark_point();
1✔
888
  res = pr_redis_remove(redis, NULL, NULL);
1✔
889
  ck_assert_msg(res < 0, "Failed to handle null module");
1✔
890
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
891
    strerror(errno), errno);
892

893
  mark_point();
1✔
894
  res = pr_redis_remove(redis, &m, NULL);
895
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
896
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
897
    strerror(errno), errno);
1✔
898

1✔
899
  key = "testkey";
900

901
  mark_point();
1✔
902
  res = pr_redis_remove(redis, &m, key);
1✔
903
  ck_assert_msg(res < 0, "Unexpectedly removed key '%s'", key);
1✔
904
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
905
    strerror(errno), errno);
906

907
  mark_point();
1✔
908
  res = pr_redis_conn_destroy(redis);
1✔
909
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
910
}
1✔
911
END_TEST
1✔
912

1✔
913
START_TEST (redis_add_test) {
1✔
914
  int res;
1✔
915
  pr_redis_t *redis;
916
  module m;
1✔
917
  const char *key;
1✔
918
  char *val;
1✔
919
  size_t valsz;
1✔
920
  time_t expires;
921

922
  mark_point();
1✔
923
  res = pr_redis_add(NULL, NULL, NULL, NULL, 0, 0);
1✔
924
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
925
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
926
    strerror(errno), errno);
927

1✔
928
  mark_point();
1✔
929
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
930
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
931
    strerror(errno));
932

933
  mark_point();
1✔
934
  res = pr_redis_add(redis, NULL, NULL, NULL, 0, 0);
1✔
935
  ck_assert_msg(res < 0, "Failed to handle null module");
1✔
936
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
937
    strerror(errno), errno);
938

939
  mark_point();
1✔
940
  res = pr_redis_add(redis, &m, NULL, NULL, 0, 0);
941
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
942
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
943
    strerror(errno), errno);
1✔
944

1✔
945
  key = "testkey";
946

947
  mark_point();
1✔
948
  res = pr_redis_add(redis, &m, key, NULL, 0, 0);
1✔
949
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
950
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
951
    strerror(errno), errno);
1✔
952

1✔
953
  val = "testval";
1✔
954
  valsz = strlen(val);
955
  expires = 0;
956

1✔
957
  mark_point();
1✔
958
  res = pr_redis_add(redis, &m, key, val, valsz, expires);
1✔
959
  ck_assert_msg(res == 0, "Failed to add key '%s', val '%s': %s", key, val,
960
    strerror(errno));
1✔
961

962
  mark_point();
1✔
963
  res = pr_redis_remove(redis, &m, key);
1✔
964
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
965

966
  expires = 3;
967

1✔
968
  mark_point();
1✔
969
  res = pr_redis_add(redis, &m, key, val, valsz, expires);
1✔
970
  ck_assert_msg(res == 0, "Failed to add key '%s', val '%s': %s", key, val,
971
    strerror(errno));
1✔
972

1✔
973
  mark_point();
1✔
974
  res = pr_redis_remove(redis, &m, key);
1✔
975
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
976

977
  mark_point();
1✔
978
  res = pr_redis_conn_destroy(redis);
1✔
979
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
980
}
1✔
981
END_TEST
1✔
982

1✔
983
START_TEST (redis_add_with_namespace_test) {
1✔
984
  int res;
1✔
985
  pr_redis_t *redis;
986
  module m;
1✔
987
  const char *prefix, *key;
1✔
988
  char *val;
1✔
989
  size_t prefixsz, valsz;
990
  time_t expires;
991

1✔
992
  mark_point();
1✔
993
  redis = pr_redis_conn_new(p, NULL, 0);
994
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
995
    strerror(errno));
1✔
996

1✔
997
  prefix = "test.";
998
  prefixsz = strlen(prefix);
999

1✔
1000
  mark_point();
1✔
1001
  res = pr_redis_conn_set_namespace(redis, &m, prefix, prefixsz);
1✔
1002
  ck_assert_msg(res == 0, "Failed to set namespace prefix '%s': %s", prefix,
1✔
1003
    strerror(errno));
1004

1✔
1005
  key = "key";
1✔
1006
  val = "val";
1✔
1007
  valsz = strlen(val);
1008
  expires = 0;
1009

1✔
1010
  mark_point();
1✔
1011
  res = pr_redis_add(redis, &m, key, val, valsz, expires);
1✔
1012
  ck_assert_msg(res == 0, "Failed to add key '%s', val '%s': %s", key, val,
1013
    strerror(errno));
1✔
1014

1✔
1015
  mark_point();
1✔
1016
  res = pr_redis_remove(redis, &m, key);
1017
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1018

1✔
1019
  mark_point();
1✔
1020
  res = pr_redis_conn_set_namespace(redis, &m, NULL, 0);
1✔
1021
  ck_assert_msg(res == 0, "Failed to set null namespace prefix: %s",
1✔
1022
    strerror(errno));
1023

1024
  mark_point();
1✔
1025
  res = pr_redis_conn_destroy(redis);
1✔
1026
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1027
}
1✔
1028
END_TEST
1✔
1029

1✔
1030
START_TEST (redis_get_test) {
1✔
1031
  int res;
1✔
1032
  pr_redis_t *redis;
1✔
1033
  module m;
1034
  const char *key;
1✔
1035
  char *val;
1✔
1036
  size_t valsz;
1✔
1037
  time_t expires;
1✔
1038
  void *data;
1039

1040
  mark_point();
1✔
1041
  data = pr_redis_get(NULL, NULL, NULL, NULL, NULL);
1✔
1042
  ck_assert_msg(data == NULL, "Failed to handle null pool");
1✔
1043
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1044
    strerror(errno), errno);
1045

1046
  mark_point();
1✔
1047
  data = pr_redis_get(p, NULL, NULL, NULL, NULL);
1✔
1048
  ck_assert_msg(data == NULL, "Failed to handle null redis");
1✔
1049
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1050
    strerror(errno), errno);
1051

1✔
1052
  mark_point();
1✔
1053
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
1054
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
1055
    strerror(errno));
1056

1057
  mark_point();
1✔
1058
  data = pr_redis_get(p, redis, NULL, NULL, NULL);
1✔
1059
  ck_assert_msg(data == NULL, "Failed to handle null module");
1✔
1060
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1061
    strerror(errno), errno);
1062

1063
  mark_point();
1✔
1064
  data = pr_redis_get(p, redis, &m, NULL, NULL);
1✔
1065
  ck_assert_msg(data == NULL, "Failed to handle null key");
1066
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1067
    strerror(errno), errno);
1✔
1068

1✔
1069
  key = "testkey";
1✔
1070
  (void) pr_redis_remove(redis, &m, key);
1071

1072
  mark_point();
1✔
1073
  data = pr_redis_get(p, redis, &m, key, NULL);
1✔
1074
  ck_assert_msg(data == NULL, "Failed to handle null valuesz");
1✔
1075
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1076
    strerror(errno), errno);
1077

1078
  mark_point();
1✔
1079
  data = pr_redis_get(p, redis, &m, key, &valsz);
1✔
1080
  ck_assert_msg(data == NULL, "Failed to handle nonexistent key");
1✔
1081
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1082
    strerror(errno), errno);
1✔
1083

1✔
1084
  val = "Hello, World!";
1✔
1085
  valsz = strlen(val);
1086
  expires = 0;
1087

1✔
1088
  mark_point();
1089
  res = pr_redis_set(redis, &m, key, val, valsz, expires);
1✔
1090
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
1✔
1091
    strerror(errno));
1✔
1092

1093
  valsz = 0;
1✔
1094

1095
  mark_point();
1096
  data = pr_redis_get(p, redis, &m, key, &valsz);
1✔
1097
  ck_assert_msg(data != NULL, "Failed to get data for key '%s': %s", key,
1✔
1098
    strerror(errno));
1✔
1099
  ck_assert_msg(valsz == strlen(val), "Expected %lu, got %lu",
1100
    (unsigned long) strlen(val), (unsigned long) valsz);
1✔
1101

1✔
1102
  mark_point();
1✔
1103
  res = pr_redis_remove(redis, &m, key);
1✔
1104
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1105

1106
  mark_point();
1✔
1107
  data = pr_redis_get(p, redis, &m, key, &valsz);
1✔
1108
  ck_assert_msg(data == NULL, "Failed to handle nonexistent key");
1✔
1109
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
1110
    strerror(errno), errno);
1111

1112
  mark_point();
1✔
1113
  res = pr_redis_conn_destroy(redis);
1✔
1114
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1115
}
1✔
1116
END_TEST
1✔
1117

1✔
1118
START_TEST (redis_get_with_namespace_test) {
1✔
1119
  int res;
1✔
1120
  pr_redis_t *redis;
1✔
1121
  module m;
1122
  const char *prefix, *key;
1123
  char *val;
1124
  size_t prefixsz, valsz;
1✔
1125
  time_t expires;
1✔
1126
  void *data;
1✔
1127

1128
  /* set a value, set the namespace, get it. */
1129

1✔
1130
  mark_point();
1✔
1131
  redis = pr_redis_conn_new(p, NULL, 0);
1132
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
1133
    strerror(errno));
1✔
1134

1135
  prefix = "prefix.";
1✔
1136
  prefixsz = strlen(prefix);
1✔
1137

1✔
1138
  key = "prefix.testkey";
1139
  (void) pr_redis_remove(redis, &m, key);
1✔
1140

1✔
1141
  val = "Hello, World!";
1✔
1142
  valsz = strlen(val);
1143
  expires = 0;
1144

1✔
1145
  mark_point();
1✔
1146
  res = pr_redis_set(redis, &m, key, val, valsz, expires);
1✔
1147
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
1148
    strerror(errno));
1149

1✔
1150
  mark_point();
1✔
1151
  res = pr_redis_conn_set_namespace(redis, &m, prefix, prefixsz);
1152
  ck_assert_msg(res == 0, "Failed to set namespace prefix '%s': %s", prefix,
1✔
1153
    strerror(errno));
1✔
1154

1✔
1155
  key = "testkey";
1156
  valsz = 0;
1✔
1157

1158
  mark_point();
1✔
1159
  data = pr_redis_get(p, redis, &m, key, &valsz);
1160
  ck_assert_msg(data != NULL, "Failed to get data for key '%s': %s", key,
1161
    strerror(errno));
1✔
1162
  ck_assert_msg(valsz == strlen(val), "Expected %lu, got %lu",
1✔
1163
    (unsigned long) strlen(val), (unsigned long) valsz);
1✔
1164
  ck_assert_msg(memcmp(data, val, valsz) == 0, "Expected '%s', got '%.*s'",
1✔
1165
    val, (int) valsz, (char *) data);
1166

1167
  mark_point();
1✔
1168
  res = pr_redis_conn_destroy(redis);
1✔
1169
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1170
}
1✔
1171
END_TEST
1✔
1172

1✔
1173
START_TEST (redis_get_str_test) {
1✔
1174
  int res;
1✔
1175
  pr_redis_t *redis;
1176
  module m;
1✔
1177
  const char *key;
1✔
1178
  size_t valsz;
1✔
1179
  time_t expires;
1✔
1180
  char *val, *str;
1181

1182
  mark_point();
1✔
1183
  str = pr_redis_get_str(NULL, NULL, NULL, NULL);
1✔
1184
  ck_assert_msg(str == NULL, "Failed to handle null pool");
1✔
1185
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1186
    strerror(errno), errno);
1187

1188
  mark_point();
1✔
1189
  str = pr_redis_get_str(p, NULL, NULL, NULL);
1✔
1190
  ck_assert_msg(str == NULL, "Failed to handle null redis");
1✔
1191
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1192
    strerror(errno), errno);
1193

1✔
1194
  mark_point();
1✔
1195
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
1196
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
1197
    strerror(errno));
1198

1199
  mark_point();
1✔
1200
  str = pr_redis_get_str(p, redis, NULL, NULL);
1✔
1201
  ck_assert_msg(str == NULL, "Failed to handle null module");
1✔
1202
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1203
    strerror(errno), errno);
1204

1205
  mark_point();
1✔
1206
  str = pr_redis_get_str(p, redis, &m, NULL);
1✔
1207
  ck_assert_msg(str == NULL, "Failed to handle null key");
1208
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1209
    strerror(errno), errno);
1✔
1210

1✔
1211
  key = "test_string";
1✔
1212
  (void) pr_redis_remove(redis, &m, key);
1213

1214
  mark_point();
1✔
1215
  str = pr_redis_get_str(p, redis, &m, key);
1✔
1216
  ck_assert_msg(str == NULL, "Failed to handle nonexistent key");
1✔
1217
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1218
    strerror(errno), errno);
1✔
1219

1✔
1220
  val = "Hello, World!";
1✔
1221
  valsz = strlen(val);
1222
  expires = 0;
1223

1✔
1224
  mark_point();
1✔
1225
  res = pr_redis_set(redis, &m, key, val, valsz, expires);
1✔
1226
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
1227
    strerror(errno));
1✔
1228

1229
  mark_point();
1230
  str = pr_redis_get_str(p, redis, &m, key);
1✔
1231
  ck_assert_msg(str != NULL, "Failed to get string for key '%s': %s", key,
1✔
1232
    strerror(errno));
1✔
1233
  ck_assert_msg(strlen(str) == strlen(val), "Expected %lu, got %lu",
1234
    (unsigned long) strlen(val), (unsigned long) strlen(str));
1✔
1235

1✔
1236
  mark_point();
1✔
1237
  res = pr_redis_remove(redis, &m, key);
1✔
1238
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1239

1240
  mark_point();
1✔
1241
  str = pr_redis_get_str(p, redis, &m, key);
1✔
1242
  ck_assert_msg(str == NULL, "Failed to handle nonexistent key");
1✔
1243
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
1244
    strerror(errno), errno);
1245

1246
  mark_point();
1✔
1247
  res = pr_redis_conn_destroy(redis);
1✔
1248
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1249
}
1✔
1250
END_TEST
1✔
1251

1✔
1252
START_TEST (redis_incr_test) {
1✔
1253
  int res;
1✔
1254
  pr_redis_t *redis;
1✔
1255
  module m;
1✔
1256
  const char *key;
1257
  char *value;
1✔
1258
  uint32_t incr;
1✔
1259
  uint64_t val = 0;
1✔
1260
  size_t valsz;
1✔
1261
  time_t expires;
1262

1263
  mark_point();
1✔
1264
  res = pr_redis_incr(NULL, NULL, NULL, 0, NULL);
1✔
1265
  ck_assert_msg(res < 0, "Failed to handle null redis");
1✔
1266
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1267
    strerror(errno), errno);
1268

1✔
1269
  mark_point();
1✔
1270
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
1271
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
1272
    strerror(errno));
1273

1274
  mark_point();
1✔
1275
  res = pr_redis_incr(redis, NULL, NULL, 0, NULL);
1✔
1276
  ck_assert_msg(res < 0, "Failed to handle null module");
1✔
1277
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1278
    strerror(errno), errno);
1279

1280
  mark_point();
1✔
1281
  res = pr_redis_incr(redis, &m, NULL, 0, NULL);
1✔
1282
  ck_assert_msg(res < 0, "Failed to handle null key");
1283
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1284
    strerror(errno), errno);
1✔
1285

1✔
1286
  key = "testval";
1✔
1287
  (void) pr_redis_remove(redis, &m, key);
1288

1289
  mark_point();
1✔
1290
  res = pr_redis_incr(redis, &m, key, 0, NULL);
1291
  ck_assert_msg(res < 0, "Failed to handle zero incr");
1✔
1292
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1293
    strerror(errno), errno);
1✔
1294

1✔
1295
  incr = 2;
1296

1297
  mark_point();
1298
  res = pr_redis_incr(redis, &m, key, incr, NULL);
1299
  ck_assert_msg(res < 0, "Failed to handle nonexistent key");
1300
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
1301
    strerror(errno), errno);
1✔
1302

1✔
1303
  /* Note: Yes, Redis wants a string, NOT the actual bytes.  Makes sense,
1304
   * I guess, given its text-based protocol.
1✔
1305
   */
1✔
1306
  value = "31";
1✔
1307
  valsz = strlen(value);
1308
  expires = 0;
1309

1✔
1310
  mark_point();
1✔
1311
  res = pr_redis_set(redis, &m, key, value, valsz, expires);
1✔
1312
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, value,
1313
    strerror(errno));
1314

1✔
1315
  mark_point();
1316
  res = pr_redis_incr(redis, &m, key, incr, NULL);
1✔
1317
  ck_assert_msg(res == 0, "Failed to increment key '%s' by %lu: %s", key,
1✔
1318
    (unsigned long) incr, strerror(errno));
1✔
1319

1320
  val = 0;
1✔
1321

1322
  mark_point();
1✔
1323
  res = pr_redis_incr(redis, &m, key, incr, &val);
1✔
1324
  ck_assert_msg(res == 0, "Failed to increment key '%s' by %lu: %s", key,
1✔
1325
    (unsigned long) incr, strerror(errno));
1326
  ck_assert_msg(val == 35, "Expected %lu, got %lu", (unsigned long) 35,
1327
    (unsigned long) val);
1✔
1328

1✔
1329
  mark_point();
1✔
1330
  res = pr_redis_remove(redis, &m, key);
1331
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
1332

1✔
1333
  /* Now, let's try incrementing a non-numeric value. */
1✔
1334
  value = "Hello, World!";
1335
  valsz = strlen(value);
1336
  expires = 0;
1✔
1337

1✔
1338
  mark_point();
1✔
1339
  res = pr_redis_set(redis, &m, key, value, valsz, expires);
1✔
1340
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, value,
1341
    strerror(errno));
1342

1✔
1343
  mark_point();
1344
  res = pr_redis_incr(redis, &m, key, incr, &val);
1✔
1345
  ck_assert_msg(res < 0, "Failed to handle non-numeric key value");
1✔
1346
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1347
    strerror(errno), errno);
1✔
1348

1349
  (void) pr_redis_remove(redis, &m, key);
1350

1✔
1351
  mark_point();
1✔
1352
  res = pr_redis_conn_destroy(redis);
1✔
1353
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1354
}
1✔
1355
END_TEST
1✔
1356

1✔
1357
START_TEST (redis_decr_test) {
1✔
1358
  int res;
1✔
1359
  pr_redis_t *redis;
1✔
1360
  module m;
1361
  const char *key;
1✔
1362
  char *value;
1✔
1363
  uint32_t decr;
1✔
1364
  uint64_t val = 0;
1✔
1365
  size_t valsz;
1366
  time_t expires;
1367

1✔
1368
  mark_point();
1✔
1369
  res = pr_redis_decr(NULL, NULL, NULL, 0, NULL);
1✔
1370
  ck_assert_msg(res < 0, "Failed to handle null redis");
1371
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1372
    strerror(errno), errno);
1✔
1373

1✔
1374
  mark_point();
1✔
1375
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
1376
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1377
    strerror(errno));
1378

1✔
1379
  mark_point();
1✔
1380
  res = pr_redis_decr(redis, NULL, NULL, 0, NULL);
1✔
1381
  ck_assert_msg(res < 0, "Failed to handle null module");
1✔
1382
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1383
    strerror(errno), errno);
1384

1✔
1385
  mark_point();
1✔
1386
  res = pr_redis_decr(redis, &m, NULL, 0, NULL);
1387
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1388
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1389
    strerror(errno), errno);
1✔
1390

1✔
1391
  key = "testval";
1392
  (void) pr_redis_remove(redis, &m, key);
1393

1✔
1394
  mark_point();
1395
  res = pr_redis_decr(redis, &m, key, 0, NULL);
1✔
1396
  ck_assert_msg(res < 0, "Failed to handle zero decr");
1✔
1397
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1398
    strerror(errno), errno);
1✔
1399

1400
  decr = 5;
1401

1402
  mark_point();
1403
  res = pr_redis_decr(redis, &m, key, decr, NULL);
1404
  ck_assert_msg(res < 0, "Failed to handle nonexistent key");
1✔
1405
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
1406
    strerror(errno), errno);
1✔
1407

1408
  /* Note: Yes, Redis wants a string, NOT the actual bytes.  Makes sense,
1✔
1409
   * I guess, given its text-based protocol.
1✔
1410
   */
1✔
1411
  value = "31";
1412
  valsz = strlen(value);
1413
  expires = 0;
1✔
1414

1✔
1415
  mark_point();
1✔
1416
  res = pr_redis_set(redis, &m, key, value, valsz, expires);
1417
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, value,
1418
    strerror(errno));
1✔
1419

1420
  mark_point();
1✔
1421
  res = pr_redis_decr(redis, &m, key, decr, NULL);
1✔
1422
  ck_assert_msg(res == 0, "Failed to decrement key '%s' by %lu: %s", key,
1✔
1423
    (unsigned long) decr, strerror(errno));
1424

1✔
1425
  val = 0;
1426

1✔
1427
  mark_point();
1✔
1428
  res = pr_redis_decr(redis, &m, key, decr, &val);
1✔
1429
  ck_assert_msg(res == 0, "Failed to decrement key '%s' by %lu: %s", key,
1430
    (unsigned long) decr, strerror(errno));
1431
  ck_assert_msg(val == 21, "Expected %lu, got %lu", (unsigned long) 21,
1✔
1432
    (unsigned long) val);
1✔
1433

1✔
1434
  mark_point();
1435
  res = pr_redis_remove(redis, &m, key);
1✔
1436
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
1437

1✔
1438
  /* Now, let's try decrementing a non-numeric value. */
1439
  value = "Hello, World!";
1440
  valsz = strlen(value);
1✔
1441
  expires = 0;
1✔
1442

1✔
1443
  mark_point();
1✔
1444
  res = pr_redis_set(redis, &m, key, value, valsz, expires);
1445
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, value,
1446
    strerror(errno));
1✔
1447

1448
  mark_point();
1✔
1449
  res = pr_redis_decr(redis, &m, key, decr, &val);
1✔
1450
  ck_assert_msg(res < 0, "Failed to handle non-numeric key value");
1✔
1451
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1452
    strerror(errno), errno);
1453

1454
  (void) pr_redis_remove(redis, &m, key);
1✔
1455

1✔
1456
  mark_point();
1✔
1457
  res = pr_redis_conn_destroy(redis);
1✔
1458
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1459
}
1✔
1460
END_TEST
1✔
1461

1✔
1462
START_TEST (redis_rename_test) {
1463
  int res;
1✔
1464
  pr_redis_t *redis;
1✔
1465
  module m;
1✔
1466
  const char *from, *to;
1✔
1467
  char *val;
1468
  size_t valsz;
1469
  time_t expires;
1✔
1470

1✔
1471
  mark_point();
1✔
1472
  res = pr_redis_rename(NULL, NULL, NULL, NULL);
1473
  ck_assert_msg(res < 0, "Failed to handle null redis");
1474
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1475
    strerror(errno), errno);
1✔
1476

1✔
1477
  mark_point();
1✔
1478
  redis = pr_redis_conn_new(p, NULL, 0);
1479
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1480
    strerror(errno));
1✔
1481

1✔
1482
  mark_point();
1✔
1483
  res = pr_redis_rename(redis, NULL, NULL, NULL);
1✔
1484
  ck_assert_msg(res < 0, "Failed to handle null module");
1485
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1486
    strerror(errno), errno);
1✔
1487

1488
  mark_point();
1✔
1489
  res = pr_redis_rename(redis, &m, NULL, NULL);
1✔
1490
  ck_assert_msg(res < 0, "Failed to handle null from");
1✔
1491
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1492
    strerror(errno), errno);
1493

1494
  from = "fromkey";
1✔
1495

1496
  mark_point();
1✔
1497
  res = pr_redis_rename(redis, &m, from, NULL);
1✔
1498
  ck_assert_msg(res < 0, "Failed to handle null to");
1✔
1499
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1500
    strerror(errno), errno);
1501

1502
  to = "tokey";
1✔
1503

1✔
1504
  mark_point();
1✔
1505
  res = pr_redis_rename(redis, &m, from, to);
1506
  ck_assert_msg(res < 0, "Failed to handle nonexistent from key");
1✔
1507
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
1508
    strerror(errno), errno);
1✔
1509

1510
  val = "testval";
1511
  valsz = strlen(val);
1✔
1512
  expires = 0;
1✔
1513

1✔
1514
  mark_point();
1515
  res = pr_redis_set(redis, &m, from, val, valsz, expires);
1516
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", from, val,
1✔
1517
    strerror(errno));
1✔
1518

1✔
1519
  mark_point();
1520
  res = pr_redis_rename(redis, &m, from, to);
1✔
1521
  ck_assert_msg(res == 0, "Failed to rename '%s' to '%s': %s", from, to,
1✔
1522
    strerror(errno));
1✔
1523

1✔
1524
  mark_point();
1525
  res = pr_redis_remove(redis, &m, to);
1526
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", to, strerror(errno));
1✔
1527

1✔
1528
  mark_point();
1✔
1529
  res = pr_redis_conn_destroy(redis);
1✔
1530
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1531
}
1✔
1532
END_TEST
1✔
1533

1✔
1534
START_TEST (redis_set_test) {
1535
  int res;
1✔
1536
  pr_redis_t *redis;
1✔
1537
  module m;
1✔
1538
  const char *key;
1✔
1539
  char *val;
1540
  size_t valsz;
1541
  time_t expires;
1✔
1542

1✔
1543
  mark_point();
1✔
1544
  res = pr_redis_set(NULL, NULL, NULL, NULL, 0, 0);
1545
  ck_assert_msg(res < 0, "Failed to handle null redis");
1546
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1547
    strerror(errno), errno);
1✔
1548

1✔
1549
  mark_point();
1✔
1550
  redis = pr_redis_conn_new(p, NULL, 0);
1551
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1552
    strerror(errno));
1✔
1553

1✔
1554
  mark_point();
1✔
1555
  res = pr_redis_set(redis, NULL, NULL, NULL, 0, 0);
1✔
1556
  ck_assert_msg(res < 0, "Failed to handle null module");
1557
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1558
    strerror(errno), errno);
1✔
1559

1560
  mark_point();
1✔
1561
  res = pr_redis_set(redis, &m, NULL, NULL, 0, 0);
1✔
1562
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1563
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1564
    strerror(errno), errno);
1565

1566
  key = "testkey";
1✔
1567

1✔
1568
  mark_point();
1✔
1569
  res = pr_redis_set(redis, &m, key, NULL, 0, 0);
1570
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
1571
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1572
    strerror(errno), errno);
1✔
1573

1574
  val = "testval";
1575
  valsz = strlen(val);
1✔
1576
  expires = 0;
1✔
1577

1✔
1578
  mark_point();
1579
  res = pr_redis_set(redis, &m, key, val, valsz, expires);
1✔
1580
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
1581
    strerror(errno));
1✔
1582

1✔
1583
  mark_point();
1✔
1584
  res = pr_redis_remove(redis, &m, key);
1585
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1586

1✔
1587
  expires = 3;
1✔
1588

1✔
1589
  mark_point();
1590
  res = pr_redis_set(redis, &m, key, val, valsz, expires);
1✔
1591
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
1✔
1592
    strerror(errno));
1✔
1593

1✔
1594
  mark_point();
1595
  res = pr_redis_remove(redis, &m, key);
1596
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
1597

1✔
1598
  mark_point();
1✔
1599
  res = pr_redis_conn_destroy(redis);
1✔
1600
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1601
}
1602
END_TEST
1✔
1603

1✔
1604
START_TEST (redis_hash_remove_test) {
1✔
1605
  int res;
1✔
1606
  pr_redis_t *redis;
1607
  module m;
1608
  const char *key;
1✔
1609

1✔
1610
  mark_point();
1✔
1611
  res = pr_redis_hash_remove(NULL, NULL, NULL);
1612
  ck_assert_msg(res < 0, "Failed to handle null redis");
1613
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1614
    strerror(errno), errno);
1✔
1615

1✔
1616
  mark_point();
1✔
1617
  redis = pr_redis_conn_new(p, NULL, 0);
1618
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1619
    strerror(errno));
1✔
1620

1✔
1621
  mark_point();
1✔
1622
  res = pr_redis_hash_remove(redis, NULL, NULL);
1✔
1623
  ck_assert_msg(res < 0, "Failed to handle null module");
1624
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1625
    strerror(errno), errno);
1✔
1626

1627
  mark_point();
1✔
1628
  res = pr_redis_hash_remove(redis, &m, NULL);
1✔
1629
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1630
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1631
    strerror(errno), errno);
1632

1633
  key = "testkey";
1✔
1634

1✔
1635
  mark_point();
1✔
1636
  res = pr_redis_hash_remove(redis, &m, key);
1✔
1637
  ck_assert_msg(res < 0, "Unexpectedly removed key '%s'", key);
1638
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1639
    strerror(errno), errno);
1✔
1640

1✔
1641
  mark_point();
1✔
1642
  res = pr_redis_conn_destroy(redis);
1✔
1643
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1644
}
1✔
1645
END_TEST
1✔
1646

1647
START_TEST (redis_hash_get_test) {
1✔
1648
  int res;
1✔
1649
  pr_redis_t *redis;
1✔
1650
  module m;
1✔
1651
  const char *key, *field;
1652
  char *val;
1653
  size_t valsz;
1✔
1654

1✔
1655
  mark_point();
1✔
1656
  res = pr_redis_hash_get(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1✔
1657
  ck_assert_msg(res < 0, "Failed to handle null pool");
1658
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1659
    strerror(errno), errno);
1✔
1660

1✔
1661
  mark_point();
1✔
1662
  res = pr_redis_hash_get(p, NULL, NULL, NULL, NULL, NULL, NULL);
1663
  ck_assert_msg(res < 0, "Failed to handle null redis");
1664
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1665
    strerror(errno), errno);
1✔
1666

1✔
1667
  mark_point();
1✔
1668
  redis = pr_redis_conn_new(p, NULL, 0);
1669
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1670
    strerror(errno));
1✔
1671

1✔
1672
  mark_point();
1✔
1673
  res = pr_redis_hash_get(p, redis, NULL, NULL, NULL, NULL, NULL);
1✔
1674
  ck_assert_msg(res < 0, "Failed to handle null module");
1675
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1676
    strerror(errno), errno);
1✔
1677

1✔
1678
  mark_point();
1679
  res = pr_redis_hash_get(p, redis, &m, NULL, NULL, NULL, NULL);
1✔
1680
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1681
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1682
    strerror(errno), errno);
1✔
1683

1684
  key = "testhashkey";
1685
  (void) pr_redis_remove(redis, &m, key);
1✔
1686

1687
  mark_point();
1✔
1688
  res = pr_redis_hash_get(p, redis, &m, key, NULL, NULL, NULL);
1✔
1689
  ck_assert_msg(res < 0, "Failed to handle null field");
1✔
1690
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1691
    strerror(errno), errno);
1692

1693
  field = "hashfield";
1✔
1694

1✔
1695
  mark_point();
1✔
1696
  res = pr_redis_hash_get(p, redis, &m, key, field, NULL, NULL);
1✔
1697
  ck_assert_msg(res < 0, "Failed to handle null value");
1698
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1699
    strerror(errno), errno);
1✔
1700

1701
  mark_point();
1✔
1702
  res = pr_redis_hash_get(p, redis, &m, key, field, (void **) &val, &valsz);
1✔
1703
  ck_assert_msg(res < 0, "Failed to handle nonexistent item");
1✔
1704
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
1705
    strerror(errno), errno);
1706

1707
  (void) pr_redis_remove(redis, &m, key);
1✔
1708

1✔
1709
  mark_point();
1✔
1710
  res = pr_redis_conn_destroy(redis);
1✔
1711
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1712
}
1✔
1713
END_TEST
1✔
1714

1715
START_TEST (redis_hash_set_test) {
1✔
1716
  int res;
1✔
1717
  pr_redis_t *redis;
1✔
1718
  module m;
1✔
1719
  const char *key, *field;
1720
  char *val;
1721
  size_t valsz;
1✔
1722

1✔
1723
  mark_point();
1✔
1724
  res = pr_redis_hash_set(NULL, NULL, NULL, NULL, NULL, 0);
1725
  ck_assert_msg(res < 0, "Failed to handle null redis");
1726
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1727
    strerror(errno), errno);
1✔
1728

1✔
1729
  mark_point();
1✔
1730
  redis = pr_redis_conn_new(p, NULL, 0);
1731
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1732
    strerror(errno));
1✔
1733

1✔
1734
  mark_point();
1✔
1735
  res = pr_redis_hash_set(redis, NULL, NULL, NULL, NULL, 0);
1✔
1736
  ck_assert_msg(res < 0, "Failed to handle null module");
1737
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1738
    strerror(errno), errno);
1✔
1739

1✔
1740
  mark_point();
1741
  res = pr_redis_hash_set(redis, &m, NULL, NULL, NULL, 0);
1✔
1742
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1743
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1744
    strerror(errno), errno);
1✔
1745

1746
  key = "testhashkey";
1747
  (void) pr_redis_remove(redis, &m, key);
1✔
1748

1749
  mark_point();
1✔
1750
  res = pr_redis_hash_set(redis, &m, key, NULL, NULL, 0);
1✔
1751
  ck_assert_msg(res < 0, "Failed to handle null field");
1✔
1752
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1753
    strerror(errno), errno);
1754

1755
  field = "hashfield";
1✔
1756

1✔
1757
  mark_point();
1758
  res = pr_redis_hash_set(redis, &m, key, field, NULL, 0);
1✔
1759
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
1760
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1761
    strerror(errno), errno);
1✔
1762

1763
  val = "hashval";
1764
  valsz = strlen(val);
1✔
1765

1✔
1766
  mark_point();
1✔
1767
  res = pr_redis_hash_set(redis, &m, key, field, val, 0);
1768
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
1769
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1770
    strerror(errno), errno);
1771

1✔
1772
  mark_point();
1✔
1773
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
1774
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
1775

1776
  val = NULL;
1✔
1777
  valsz = 0;
1✔
1778

1779
  mark_point();
1780
  res = pr_redis_hash_get(p, redis, &m, key, field, (void **) &val, &valsz);
1✔
1781
  ck_assert_msg(res == 0, "Failed to get item: %s", strerror(errno));
1✔
1782
  ck_assert_msg(valsz == 7, "Expected item length 7, got %lu",
1✔
1783
    (unsigned long) valsz);
1784
  ck_assert_msg(val != NULL, "Failed to get value from hash");
1✔
1785
  ck_assert_msg(memcmp(val, "hashval", valsz) == 0,
1✔
1786
    "Expected 'hashval', got '%.*s'", (int) valsz, val);
1✔
1787

1✔
1788
  mark_point();
1789
  res = pr_redis_hash_remove(redis, &m, key);
1790
  ck_assert_msg(res == 0, "Failed to remove hash: %s", strerror(errno));
1✔
1791

1✔
1792
  mark_point();
1✔
1793
  res = pr_redis_conn_destroy(redis);
1✔
1794
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1795
}
1✔
1796
END_TEST
1✔
1797

1798
START_TEST (redis_hash_delete_test) {
1✔
1799
  int res;
1✔
1800
  pr_redis_t *redis;
1✔
1801
  module m;
1✔
1802
  const char *key, *field;
1803
  char *val;
1804
  size_t valsz;
1✔
1805

1✔
1806
  mark_point();
1✔
1807
  res = pr_redis_hash_delete(NULL, NULL, NULL, NULL);
1808
  ck_assert_msg(res < 0, "Failed to handle null redis");
1809
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1810
    strerror(errno), errno);
1✔
1811

1✔
1812
  mark_point();
1✔
1813
  redis = pr_redis_conn_new(p, NULL, 0);
1814
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1815
    strerror(errno));
1✔
1816

1✔
1817
  mark_point();
1✔
1818
  res = pr_redis_hash_delete(redis, NULL, NULL, NULL);
1✔
1819
  ck_assert_msg(res < 0, "Failed to handle null module");
1820
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1821
    strerror(errno), errno);
1✔
1822

1✔
1823
  mark_point();
1824
  res = pr_redis_hash_delete(redis, &m, NULL, NULL);
1✔
1825
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1826
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1827
    strerror(errno), errno);
1✔
1828

1829
  key = "testhashkey";
1830
  (void) pr_redis_remove(redis, &m, key);
1✔
1831

1832
  mark_point();
1✔
1833
  res = pr_redis_hash_delete(redis, &m, key, NULL);
1✔
1834
  ck_assert_msg(res < 0, "Failed to handle null field");
1✔
1835
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1836
    strerror(errno), errno);
1837

1838
  field = "hashfield";
1✔
1839

1✔
1840
  mark_point();
1841
  res = pr_redis_hash_delete(redis, &m, key, field);
1✔
1842
  ck_assert_msg(res < 0, "Failed to handle nonexistent field");
1✔
1843
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
1844
    strerror(errno), errno);
1845

1✔
1846
  val = "hashval";
1✔
1847
  valsz = strlen(val);
1✔
1848

1849
  mark_point();
1850
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1851
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1852

1853
  mark_point();
1✔
1854
  res = pr_redis_hash_delete(redis, &m, key, field);
1✔
1855
  ck_assert_msg(res == 0, "Failed to delete field: %s", strerror(errno));
1✔
1856

1857
  /* Note that we add this item back, just so that the hash is NOT empty when
1✔
1858
   * we go to remove it entirely.
1859
   */
1✔
1860

1✔
1861
  mark_point();
1✔
1862
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
1863
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1864

1865
  (void) pr_redis_remove(redis, &m, key);
1✔
1866

1✔
1867
  mark_point();
1✔
1868
  res = pr_redis_conn_destroy(redis);
1✔
1869
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1870
}
1✔
1871
END_TEST
1✔
1872

1✔
1873
START_TEST (redis_hash_count_test) {
1874
  int res;
1✔
1875
  pr_redis_t *redis;
1✔
1876
  module m;
1✔
1877
  const char *key, *field;
1✔
1878
  uint64_t count = 0;
1879
  char *val;
1880
  size_t valsz;
1✔
1881

1✔
1882
  mark_point();
1✔
1883
  res = pr_redis_hash_count(NULL, NULL, NULL, NULL);
1884
  ck_assert_msg(res < 0, "Failed to handle null redis");
1885
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1886
    strerror(errno), errno);
1✔
1887

1✔
1888
  mark_point();
1✔
1889
  redis = pr_redis_conn_new(p, NULL, 0);
1890
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1891
    strerror(errno));
1✔
1892

1✔
1893
  mark_point();
1✔
1894
  res = pr_redis_hash_count(redis, NULL, NULL, NULL);
1✔
1895
  ck_assert_msg(res < 0, "Failed to handle null module");
1896
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1897
    strerror(errno), errno);
1✔
1898

1✔
1899
  mark_point();
1900
  res = pr_redis_hash_count(redis, &m, NULL, NULL);
1✔
1901
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1902
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1903
    strerror(errno), errno);
1✔
1904

1905
  key = "testhashkey";
1906
  (void) pr_redis_remove(redis, &m, key);
1✔
1907

1✔
1908
  mark_point();
1✔
1909
  res = pr_redis_hash_count(redis, &m, key, NULL);
1910
  ck_assert_msg(res < 0, "Failed to handle null count");
1911
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1912
    strerror(errno), errno);
1✔
1913

1✔
1914
  mark_point();
1915
  res = pr_redis_hash_count(redis, &m, key, &count);
1✔
1916
  ck_assert_msg(res == 0, "Failed to get count using key '%s': %s", key,
1✔
1917
    strerror(errno));
1✔
1918

1919
  field = "hashfield";
1✔
1920
  val = "hashval";
1✔
1921
  valsz = strlen(val);
1✔
1922

1✔
1923
  mark_point();
1924
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
1925
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1926

1✔
1927
  mark_point();
1✔
1928
  res = pr_redis_hash_count(redis, &m, key, &count);
1✔
1929
  ck_assert_msg(res == 0, "Failed to get count: %s", strerror(errno));
1✔
1930
  ck_assert_msg(count == 1, "Expected 1, got %lu", (unsigned long) count);
1931

1932
  (void) pr_redis_remove(redis, &m, key);
1✔
1933

1✔
1934
  mark_point();
1✔
1935
  res = pr_redis_conn_destroy(redis);
1✔
1936
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
1937
}
1✔
1938
END_TEST
1✔
1939

1940
START_TEST (redis_hash_exists_test) {
1✔
1941
  int res;
1✔
1942
  pr_redis_t *redis;
1✔
1943
  module m;
1✔
1944
  const char *key, *field;
1945
  char *val;
1946
  size_t valsz;
1✔
1947

1✔
1948
  mark_point();
1✔
1949
  res = pr_redis_hash_exists(NULL, NULL, NULL, NULL);
1950
  ck_assert_msg(res < 0, "Failed to handle null redis");
1951
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1952
    strerror(errno), errno);
1✔
1953

1✔
1954
  mark_point();
1✔
1955
  redis = pr_redis_conn_new(p, NULL, 0);
1956
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1957
    strerror(errno));
1✔
1958

1✔
1959
  mark_point();
1✔
1960
  res = pr_redis_hash_exists(redis, NULL, NULL, NULL);
1✔
1961
  ck_assert_msg(res < 0, "Failed to handle null module");
1962
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1963
    strerror(errno), errno);
1✔
1964

1✔
1965
  mark_point();
1966
  res = pr_redis_hash_exists(redis, &m, NULL, NULL);
1✔
1967
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
1968
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1969
    strerror(errno), errno);
1✔
1970

1971
  key = "testhashkey";
1972
  (void) pr_redis_remove(redis, &m, key);
1✔
1973

1974
  mark_point();
1✔
1975
  res = pr_redis_hash_exists(redis, &m, key, NULL);
1✔
1976
  ck_assert_msg(res < 0, "Failed to handle null field");
1✔
1977
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1978
    strerror(errno), errno);
1✔
1979

1✔
1980
  field = "hashfield";
1981

1✔
1982
  mark_point();
1✔
1983
  res = pr_redis_hash_exists(redis, &m, key, field);
1✔
1984
  ck_assert_msg(res == FALSE, "Failed to handle nonexistent field");
1985

1✔
1986
  val = "hashval";
1✔
1987
  valsz = strlen(val);
1✔
1988

1989
  mark_point();
1✔
1990
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1991
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
1992

1✔
1993
  mark_point();
1✔
1994
  res = pr_redis_hash_exists(redis, &m, key, field);
1✔
1995
  ck_assert_msg(res == TRUE, "Failed to handle existing field");
1996

1997
  (void) pr_redis_remove(redis, &m, key);
1✔
1998

1✔
1999
  mark_point();
1✔
2000
  res = pr_redis_conn_destroy(redis);
1✔
2001
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2002
}
1✔
2003
END_TEST
1✔
2004

1✔
2005
START_TEST (redis_hash_incr_test) {
2006
  int res;
1✔
2007
  pr_redis_t *redis;
1✔
2008
  module m;
1✔
2009
  const char *key, *field;
1✔
2010
  int64_t num;
2011
  char *val;
2012
  size_t valsz;
1✔
2013

1✔
2014
  mark_point();
1✔
2015
  res = pr_redis_hash_incr(NULL, NULL, NULL, NULL, 0, NULL);
2016
  ck_assert_msg(res < 0, "Failed to handle null redis");
2017
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2018
    strerror(errno), errno);
1✔
2019

1✔
2020
  mark_point();
1✔
2021
  redis = pr_redis_conn_new(p, NULL, 0);
2022
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2023
    strerror(errno));
1✔
2024

1✔
2025
  mark_point();
1✔
2026
  res = pr_redis_hash_incr(redis, NULL, NULL, NULL, 0, NULL);
1✔
2027
  ck_assert_msg(res < 0, "Failed to handle null module");
2028
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2029
    strerror(errno), errno);
1✔
2030

1✔
2031
  mark_point();
2032
  res = pr_redis_hash_incr(redis, &m, NULL, NULL, 0, NULL);
1✔
2033
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2034
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2035
    strerror(errno), errno);
1✔
2036

2037
  key = "testhashkey";
2038
  (void) pr_redis_remove(redis, &m, key);
1✔
2039

2040
  mark_point();
1✔
2041
  res = pr_redis_hash_incr(redis, &m, key, NULL, 0, NULL);
1✔
2042
  ck_assert_msg(res < 0, "Failed to handle null field");
1✔
2043
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2044
    strerror(errno), errno);
2045

2046
  field = "hashfield";
1✔
2047

1✔
2048
  mark_point();
2049
  res = pr_redis_hash_incr(redis, &m, key, field, 0, NULL);
1✔
2050
  ck_assert_msg(res < 0, "Failed to handle nonexistent field");
1✔
2051
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
2052
    strerror(errno), errno);
2053

1✔
2054
  val = "1";
1✔
2055
  valsz = strlen(val);
1✔
2056

2057
  mark_point();
1✔
2058
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
2059
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
2060

1✔
2061
  mark_point();
2062
  res = pr_redis_hash_incr(redis, &m, key, field, 0, NULL);
1✔
2063
  ck_assert_msg(res == 0, "Failed to handle existing field: %s", strerror(errno));
1✔
2064

1✔
2065
  mark_point();
1✔
2066
  res = pr_redis_hash_incr(redis, &m, key, field, 1, &num);
2067
  ck_assert_msg(res == 0, "Failed to handle existing field: %s", strerror(errno));
1✔
2068
  ck_assert_msg(num == 2, "Expected 2, got %lu", (unsigned long) num);
2069

1✔
2070
  mark_point();
1✔
2071
  res = pr_redis_hash_incr(redis, &m, key, field, -3, &num);
1✔
2072
  ck_assert_msg(res == 0, "Failed to handle existing field: %s", strerror(errno));
1✔
2073
  ck_assert_msg(num == -1, "Expected -1, got %lu", (unsigned long) num);
2074

2075
  (void) pr_redis_remove(redis, &m, key);
1✔
2076

1✔
2077
  mark_point();
1✔
2078
  res = pr_redis_conn_destroy(redis);
1✔
2079
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2080
}
1✔
2081
END_TEST
1✔
2082

1✔
2083
START_TEST (redis_hash_keys_test) {
2084
  int res;
1✔
2085
  pr_redis_t *redis;
1✔
2086
  module m;
1✔
2087
  const char *key, *field;
1✔
2088
  char *val;
2089
  size_t valsz;
2090
  array_header *fields = NULL;
1✔
2091

1✔
2092
  mark_point();
1✔
2093
  res = pr_redis_hash_keys(NULL, NULL, NULL, NULL, NULL);
1✔
2094
  ck_assert_msg(res < 0, "Failed to handle null pool");
2095
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2096
    strerror(errno), errno);
1✔
2097

1✔
2098
  mark_point();
1✔
2099
  res = pr_redis_hash_keys(p, NULL, NULL, NULL, NULL);
2100
  ck_assert_msg(res < 0, "Failed to handle null redis");
2101
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2102
    strerror(errno), errno);
1✔
2103

1✔
2104
  mark_point();
1✔
2105
  redis = pr_redis_conn_new(p, NULL, 0);
2106
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2107
    strerror(errno));
1✔
2108

1✔
2109
  mark_point();
1✔
2110
  res = pr_redis_hash_keys(p, redis, NULL, NULL, NULL);
1✔
2111
  ck_assert_msg(res < 0, "Failed to handle null module");
2112
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2113
    strerror(errno), errno);
1✔
2114

1✔
2115
  mark_point();
2116
  res = pr_redis_hash_keys(p, redis, &m, NULL, NULL);
1✔
2117
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2118
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2119
    strerror(errno), errno);
1✔
2120

2121
  key = "testhashkey";
2122
  (void) pr_redis_remove(redis, &m, key);
1✔
2123

1✔
2124
  mark_point();
1✔
2125
  res = pr_redis_hash_keys(p, redis, &m, key, NULL);
1✔
2126
  ck_assert_msg(res < 0, "Failed to handle null fields");
2127
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2128
    strerror(errno), errno);
2129

2130
  mark_point();
1✔
2131
  res = pr_redis_hash_keys(p, redis, &m, key, &fields);
1✔
2132
  ck_assert_msg(res < 0, "Failed to handle nonexistent fields");
1✔
2133
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
2134
    strerror(errno), errno);
1✔
2135

1✔
2136
  /* Add some fields */
1✔
2137

2138
  field = "foo";
1✔
2139
  val = "1";
1✔
2140
  valsz = strlen(val);
1✔
2141

2142
  mark_point();
1✔
2143
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
2144
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
2145

2146
  field = "bar";
1✔
2147
  val = "baz quxx";
2148
  valsz = strlen(val);
1✔
2149

1✔
2150
  mark_point();
1✔
2151
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
2152
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
2153

2154
  fields = NULL;
1✔
2155

2156
  mark_point();
1✔
2157
  res = pr_redis_hash_keys(p, redis, &m, key, &fields);
1✔
2158
  ck_assert_msg(res == 0, "Failed to handle existing fields: %s", strerror(errno));
1✔
2159
  ck_assert_msg(fields != NULL, "Failed to get hash fields");
1✔
2160
  ck_assert_msg(fields->nelts == 2, "Expected 2, got %u", fields->nelts);
2161

2162
  (void) pr_redis_remove(redis, &m, key);
1✔
2163

1✔
2164
  mark_point();
1✔
2165
  res = pr_redis_conn_destroy(redis);
1✔
2166
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2167
}
1✔
2168
END_TEST
1✔
2169

1✔
2170
START_TEST (redis_hash_values_test) {
2171
  int res;
1✔
2172
  pr_redis_t *redis;
1✔
2173
  module m;
1✔
2174
  const char *key, *field;
1✔
2175
  char *val;
2176
  size_t valsz;
2177
  array_header *values = NULL;
1✔
2178

1✔
2179
  mark_point();
1✔
2180
  res = pr_redis_hash_values(NULL, NULL, NULL, NULL, NULL);
1✔
2181
  ck_assert_msg(res < 0, "Failed to handle null pool");
2182
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2183
    strerror(errno), errno);
1✔
2184

1✔
2185
  mark_point();
1✔
2186
  res = pr_redis_hash_values(p, NULL, NULL, NULL, NULL);
2187
  ck_assert_msg(res < 0, "Failed to handle null redis");
2188
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2189
    strerror(errno), errno);
1✔
2190

1✔
2191
  mark_point();
1✔
2192
  redis = pr_redis_conn_new(p, NULL, 0);
2193
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2194
    strerror(errno));
1✔
2195

1✔
2196
  mark_point();
1✔
2197
  res = pr_redis_hash_values(p, redis, NULL, NULL, NULL);
1✔
2198
  ck_assert_msg(res < 0, "Failed to handle null module");
2199
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2200
    strerror(errno), errno);
1✔
2201

1✔
2202
  mark_point();
2203
  res = pr_redis_hash_values(p, redis, &m, NULL, NULL);
1✔
2204
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2205
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2206
    strerror(errno), errno);
1✔
2207

2208
  key = "testhashkey";
2209
  (void) pr_redis_remove(redis, &m, key);
1✔
2210

1✔
2211
  mark_point();
1✔
2212
  res = pr_redis_hash_values(p, redis, &m, key, NULL);
1✔
2213
  ck_assert_msg(res < 0, "Failed to handle null values");
2214
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2215
    strerror(errno), errno);
2216

2217
  mark_point();
1✔
2218
  res = pr_redis_hash_values(p, redis, &m, key, &values);
1✔
2219
  ck_assert_msg(res < 0, "Failed to handle nonexistent values");
1✔
2220
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
2221
    strerror(errno), errno);
1✔
2222

1✔
2223
  /* Add some fields */
1✔
2224

2225
  field = "foo";
1✔
2226
  val = "1";
1✔
2227
  valsz = strlen(val);
1✔
2228

2229
  mark_point();
1✔
2230
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
2231
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
2232

2233
  field = "bar";
1✔
2234
  val = "baz quxx";
2235
  valsz = strlen(val);
1✔
2236

1✔
2237
  mark_point();
1✔
2238
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
2239
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
2240

2241
  values = NULL;
1✔
2242

2243
  mark_point();
1✔
2244
  res = pr_redis_hash_values(p, redis, &m, key, &values);
1✔
2245
  ck_assert_msg(res == 0, "Failed to handle existing values: %s", strerror(errno));
1✔
2246
  ck_assert_msg(values != NULL, "Failed to get hash values");
1✔
2247
  ck_assert_msg(values->nelts == 2, "Expected 2, got %u", values->nelts);
2248

2249
  (void) pr_redis_remove(redis, &m, key);
1✔
2250

1✔
2251
  mark_point();
1✔
2252
  res = pr_redis_conn_destroy(redis);
1✔
2253
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2254
}
1✔
2255
END_TEST
1✔
2256

1✔
2257
START_TEST (redis_hash_getall_test) {
2258
  int res;
1✔
2259
  pr_redis_t *redis;
1✔
2260
  module m;
1✔
2261
  const char *key, *field;
1✔
2262
  char *val;
2263
  size_t valsz;
2264
  pr_table_t *hash = NULL;
1✔
2265

1✔
2266
  mark_point();
1✔
2267
  res = pr_redis_hash_getall(NULL, NULL, NULL, NULL, NULL);
1✔
2268
  ck_assert_msg(res < 0, "Failed to handle null pool");
2269
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2270
    strerror(errno), errno);
1✔
2271

1✔
2272
  mark_point();
1✔
2273
  res = pr_redis_hash_getall(p, NULL, NULL, NULL, NULL);
2274
  ck_assert_msg(res < 0, "Failed to handle null redis");
2275
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2276
    strerror(errno), errno);
1✔
2277

1✔
2278
  mark_point();
1✔
2279
  redis = pr_redis_conn_new(p, NULL, 0);
2280
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2281
    strerror(errno));
1✔
2282

1✔
2283
  mark_point();
1✔
2284
  res = pr_redis_hash_getall(p, redis, NULL, NULL, NULL);
1✔
2285
  ck_assert_msg(res < 0, "Failed to handle null module");
2286
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2287
    strerror(errno), errno);
1✔
2288

1✔
2289
  mark_point();
2290
  res = pr_redis_hash_getall(p, redis, &m, NULL, NULL);
1✔
2291
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2292
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2293
    strerror(errno), errno);
1✔
2294

2295
  key = "testhashkey";
2296
  (void) pr_redis_remove(redis, &m, key);
1✔
2297

1✔
2298
  mark_point();
1✔
2299
  res = pr_redis_hash_getall(p, redis, &m, key, NULL);
1✔
2300
  ck_assert_msg(res < 0, "Failed to handle null hash");
2301
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2302
    strerror(errno), errno);
2303

2304
  mark_point();
1✔
2305
  res = pr_redis_hash_getall(p, redis, &m, key, &hash);
1✔
2306
  ck_assert_msg(res < 0, "Failed to handle nonexistent hash");
1✔
2307
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
2308
    strerror(errno), errno);
1✔
2309

1✔
2310
  /* Add some fields */
1✔
2311

2312
  field = "foo";
1✔
2313
  val = "1";
1✔
2314
  valsz = strlen(val);
1✔
2315

2316
  mark_point();
1✔
2317
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
2318
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
2319

2320
  field = "bar";
1✔
2321
  val = "baz quxx";
2322
  valsz = strlen(val);
1✔
2323

1✔
2324
  mark_point();
1✔
2325
  res = pr_redis_hash_set(redis, &m, key, field, val, valsz);
1✔
2326
  ck_assert_msg(res == 0, "Failed to set item: %s", strerror(errno));
1✔
2327

1✔
2328
  hash = NULL;
2329

1✔
2330
  mark_point();
2331
  res = pr_redis_hash_getall(p, redis, &m, key, &hash);
1✔
2332
  ck_assert_msg(res == 0, "Failed to handle existing fields: %s", strerror(errno));
1✔
2333
  ck_assert_msg(hash != NULL, "Failed to get hash");
1✔
2334
  res = pr_table_count(hash);
1✔
2335
  ck_assert_msg(res == 2, "Expected 2, got %d", res);
2336

2337
  (void) pr_redis_remove(redis, &m, key);
1✔
2338

1✔
2339
  mark_point();
1✔
2340
  res = pr_redis_conn_destroy(redis);
1✔
2341
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2342
}
1✔
2343
END_TEST
1✔
2344

1✔
2345
START_TEST (redis_hash_setall_test) {
1✔
2346
  int res;
2347
  pr_redis_t *redis;
1✔
2348
  module m;
1✔
2349
  const char *key, *field;
1✔
2350
  char *val;
1✔
2351
  size_t valsz;
2352
  pr_table_t *hash = NULL;
2353
  uint64_t count = 0;
1✔
2354

1✔
2355
  mark_point();
1✔
2356
  res = pr_redis_hash_setall(NULL, NULL, NULL, NULL);
2357
  ck_assert_msg(res < 0, "Failed to handle null redis");
2358
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2359
    strerror(errno), errno);
1✔
2360

1✔
2361
  mark_point();
1✔
2362
  redis = pr_redis_conn_new(p, NULL, 0);
2363
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2364
    strerror(errno));
1✔
2365

1✔
2366
  mark_point();
1✔
2367
  res = pr_redis_hash_setall(redis, NULL, NULL, NULL);
1✔
2368
  ck_assert_msg(res < 0, "Failed to handle null module");
2369
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2370
    strerror(errno), errno);
1✔
2371

1✔
2372
  mark_point();
2373
  res = pr_redis_hash_setall(redis, &m, NULL, NULL);
1✔
2374
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2375
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2376
    strerror(errno), errno);
1✔
2377

2378
  key = "testhashkey";
2379
  (void) pr_redis_remove(redis, &m, key);
1✔
2380

2381
  mark_point();
1✔
2382
  res = pr_redis_hash_setall(redis, &m, key, NULL);
1✔
2383
  ck_assert_msg(res < 0, "Failed to handle null hash");
1✔
2384
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2385
    strerror(errno), errno);
2386

2387
  hash = pr_table_alloc(p, 0);
2388

1✔
2389
  mark_point();
1✔
2390
  res = pr_redis_hash_setall(redis, &m, key, hash);
1✔
2391
  ck_assert_msg(res < 0, "Failed to handle empty hash");
1✔
2392
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2393
    strerror(errno), errno);
1✔
2394

1✔
2395
  /* Add some fields */
1✔
2396
  field = "foo";
1✔
2397
  val = "1";
2398
  valsz = strlen(val);
1✔
2399
  (void) pr_table_add_dup(hash, pstrdup(p, field), val, valsz);
1✔
2400

1✔
2401
  field = "bar";
2402
  val = "baz quxx";
1✔
2403
  valsz = strlen(val);
1✔
2404
  (void) pr_table_add_dup(hash, pstrdup(p, field), val, valsz);
1✔
2405

1✔
2406
  mark_point();
2407
  res = pr_redis_hash_setall(redis, &m, key, hash);
1✔
2408
  ck_assert_msg(res == 0, "Failed to set hash: %s", strerror(errno));
2409

1✔
2410
  mark_point();
1✔
2411
  res = pr_redis_hash_count(redis, &m, key, &count);
1✔
2412
  ck_assert_msg(res == 0, "Failed to count hash: %s", strerror(errno));
1✔
2413
  ck_assert_msg(count == 2, "Expected 2, got %lu", (unsigned long) count);
2414

2415
  (void) pr_redis_remove(redis, &m, key);
1✔
2416

1✔
2417
  mark_point();
1✔
2418
  res = pr_redis_conn_destroy(redis);
1✔
2419
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2420
}
2421
END_TEST
1✔
2422

1✔
2423
START_TEST (redis_list_remove_test) {
1✔
2424
  int res;
1✔
2425
  pr_redis_t *redis;
2426
  module m;
2427
  const char *key;
1✔
2428

1✔
2429
  mark_point();
1✔
2430
  res = pr_redis_list_remove(NULL, NULL, NULL);
2431
  ck_assert_msg(res < 0, "Failed to handle null redis");
2432
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2433
    strerror(errno), errno);
1✔
2434

1✔
2435
  mark_point();
1✔
2436
  redis = pr_redis_conn_new(p, NULL, 0);
2437
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2438
    strerror(errno));
1✔
2439

1✔
2440
  mark_point();
1✔
2441
  res = pr_redis_list_remove(redis, NULL, NULL);
1✔
2442
  ck_assert_msg(res < 0, "Failed to handle null module");
2443
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2444
    strerror(errno), errno);
1✔
2445

2446
  mark_point();
1✔
2447
  res = pr_redis_list_remove(redis, &m, NULL);
1✔
2448
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2449
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2450
    strerror(errno), errno);
2451

2452
  key = "testlistkey";
1✔
2453

1✔
2454
  mark_point();
1✔
2455
  res = pr_redis_list_remove(redis, &m, key);
1✔
2456
  ck_assert_msg(res < 0, "Failed to handle nonexistent list");
2457
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
2458
    strerror(errno), errno);
1✔
2459

1✔
2460
  mark_point();
1✔
2461
  res = pr_redis_conn_destroy(redis);
1✔
2462
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2463
}
1✔
2464
END_TEST
1✔
2465

2466
START_TEST (redis_list_append_test) {
1✔
2467
  int res;
1✔
2468
  pr_redis_t *redis;
1✔
2469
  module m;
1✔
2470
  const char *key;
2471
  char *val;
2472
  size_t valsz;
1✔
2473

1✔
2474
  mark_point();
1✔
2475
  res = pr_redis_list_append(NULL, NULL, NULL, NULL, 0);
2476
  ck_assert_msg(res < 0, "Failed to handle null redis");
2477
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2478
    strerror(errno), errno);
1✔
2479

1✔
2480
  mark_point();
1✔
2481
  redis = pr_redis_conn_new(p, NULL, 0);
2482
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2483
    strerror(errno));
1✔
2484

1✔
2485
  mark_point();
1✔
2486
  res = pr_redis_list_append(redis, NULL, NULL, NULL, 0);
1✔
2487
  ck_assert_msg(res < 0, "Failed to handle null module");
2488
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2489
    strerror(errno), errno);
1✔
2490

1✔
2491
  mark_point();
2492
  res = pr_redis_list_append(redis, &m, NULL, NULL, 0);
1✔
2493
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2494
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2495
    strerror(errno), errno);
1✔
2496

2497
  key = "testlistkey";
2498
  (void) pr_redis_remove(redis, &m, key);
1✔
2499

2500
  mark_point();
1✔
2501
  res = pr_redis_list_append(redis, &m, key, NULL, 0);
1✔
2502
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
2503
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2504
    strerror(errno), errno);
2505

2506
  val = "Some JSON here";
1✔
2507

2508
  mark_point();
1✔
2509
  res = pr_redis_list_append(redis, &m, key, val, 0);
1✔
2510
  ck_assert_msg(res < 0, "Failed to handle empty value");
2511
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2512
    strerror(errno), errno);
1✔
2513

1✔
2514
  valsz = strlen(val);
2515

2516
  mark_point();
1✔
2517
  (void) pr_redis_list_remove(redis, &m, key);
1✔
2518

1✔
2519
  mark_point();
2520
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
2521
  ck_assert_msg(res == 0, "Failed to append to list '%s': %s", key,
1✔
2522
    strerror(errno));
1✔
2523

1✔
2524
  mark_point();
2525
  res = pr_redis_list_remove(redis, &m, key);
2526
  ck_assert_msg(res == 0, "Failed to remove list '%s': %s", key, strerror(errno));
1✔
2527

1✔
2528
  mark_point();
1✔
2529
  res = pr_redis_conn_destroy(redis);
1✔
2530
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2531
}
1✔
2532
END_TEST
1✔
2533

1✔
2534
START_TEST (redis_list_count_test) {
2535
  int res;
1✔
2536
  pr_redis_t *redis;
1✔
2537
  module m;
1✔
2538
  const char *key;
1✔
2539
  uint64_t count = 0;
2540
  char *val;
2541
  size_t valsz;
1✔
2542

1✔
2543
  mark_point();
1✔
2544
  res = pr_redis_list_count(NULL, NULL, NULL, NULL);
2545
  ck_assert_msg(res < 0, "Failed to handle null redis");
2546
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2547
    strerror(errno), errno);
1✔
2548

1✔
2549
  mark_point();
1✔
2550
  redis = pr_redis_conn_new(p, NULL, 0);
2551
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2552
    strerror(errno));
1✔
2553

1✔
2554
  mark_point();
1✔
2555
  res = pr_redis_list_count(redis, NULL, NULL, NULL);
1✔
2556
  ck_assert_msg(res < 0, "Failed to handle null module");
2557
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2558
    strerror(errno), errno);
1✔
2559

1✔
2560
  mark_point();
2561
  res = pr_redis_list_count(redis, &m, NULL, NULL);
1✔
2562
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2563
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2564
    strerror(errno), errno);
1✔
2565

2566
  key = "testlistkey";
2567
  (void) pr_redis_remove(redis, &m, key);
1✔
2568

1✔
2569
  mark_point();
1✔
2570
  res = pr_redis_list_count(redis, &m, key, NULL);
1✔
2571
  ck_assert_msg(res < 0, "Failed to handle null count");
2572
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2573
    strerror(errno), errno);
1✔
2574

2575
  mark_point();
1✔
2576
  res = pr_redis_list_count(redis, &m, key, &count);
1✔
2577
  ck_assert_msg(res == 0, "Failed to get list count: %s", strerror(errno));
1✔
2578
  ck_assert_msg(count == 0, "Expected 0, got %lu", (unsigned long) count);
2579

2580
  val = "Some JSON here";
1✔
2581
  valsz = strlen(val);
1✔
2582

1✔
2583
  mark_point();
1✔
2584
  res = pr_redis_list_append(redis, &m, key, val, valsz);
2585
  ck_assert_msg(res == 0, "Failed to append to list '%s': %s", key,
1✔
2586
    strerror(errno));
2587

1✔
2588
  mark_point();
1✔
2589
  res = pr_redis_list_count(redis, &m, key, &count);
1✔
2590
  ck_assert_msg(res == 0, "Failed to get list count: %s", strerror(errno));
1✔
2591
  ck_assert_msg(count == 1, "Expected 1, got %lu", (unsigned long) count);
2592

2593
  (void) pr_redis_remove(redis, &m, key);
1✔
2594

1✔
2595
  mark_point();
1✔
2596
  res = pr_redis_conn_destroy(redis);
1✔
2597
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2598
}
1✔
2599
END_TEST
1✔
2600

2601
START_TEST (redis_list_delete_test) {
1✔
2602
  int res;
1✔
2603
  pr_redis_t *redis;
1✔
2604
  module m;
1✔
2605
  const char *key;
2606
  char *val;
2607
  size_t valsz;
1✔
2608

1✔
2609
  mark_point();
1✔
2610
  res = pr_redis_list_delete(NULL, NULL, NULL, NULL, 0);
2611
  ck_assert_msg(res < 0, "Failed to handle null redis");
2612
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2613
    strerror(errno), errno);
1✔
2614

1✔
2615
  mark_point();
1✔
2616
  redis = pr_redis_conn_new(p, NULL, 0);
2617
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2618
    strerror(errno));
1✔
2619

1✔
2620
  mark_point();
1✔
2621
  res = pr_redis_list_delete(redis, NULL, NULL, NULL, 0);
1✔
2622
  ck_assert_msg(res < 0, "Failed to handle null module");
2623
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2624
    strerror(errno), errno);
1✔
2625

1✔
2626
  mark_point();
2627
  res = pr_redis_list_delete(redis, &m, NULL, NULL, 0);
1✔
2628
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2629
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2630
    strerror(errno), errno);
1✔
2631

2632
  key = "testlistkey";
2633
  (void) pr_redis_remove(redis, &m, key);
1✔
2634

2635
  mark_point();
1✔
2636
  res = pr_redis_list_delete(redis, &m, key, NULL, 0);
1✔
2637
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
2638
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2639
    strerror(errno), errno);
2640

2641
  val = "Some JSON here";
1✔
2642

2643
  mark_point();
1✔
2644
  res = pr_redis_list_delete(redis, &m, key, val, 0);
1✔
2645
  ck_assert_msg(res < 0, "Failed to handle empty value");
2646
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2647
    strerror(errno), errno);
1✔
2648

1✔
2649
  valsz = strlen(val);
1✔
2650

2651
  mark_point();
2652
  (void) pr_redis_list_remove(redis, &m, key);
1✔
2653

1✔
2654
  mark_point();
1✔
2655
  res = pr_redis_list_delete(redis, &m, key, val, valsz);
2656
  ck_assert_msg(res < 0, "Failed to handle nonexistent items");
2657
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
2658
    strerror(errno), errno);
1✔
2659

1✔
2660
  mark_point();
2661
  res = pr_redis_list_append(redis, &m, key, val, valsz);
2662
  ck_assert_msg(res == 0, "Failed to append to list '%s': %s", key,
2663
    strerror(errno));
2664

2665
  mark_point();
1✔
2666
  res = pr_redis_list_delete(redis, &m, key, val, valsz);
1✔
2667
  ck_assert_msg(res == 0, "Failed to handle existing items");
1✔
2668

2669
  /* Note that we add this item back, just so that the list is NOT empty when
2670
   * we go to remove it entirely.
1✔
2671
   */
1✔
2672

1✔
2673
  mark_point();
2674
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
2675
  ck_assert_msg(res == 0, "Failed to append to list '%s': %s", key,
1✔
2676
    strerror(errno));
1✔
2677

1✔
2678
  mark_point();
2679
  res = pr_redis_list_remove(redis, &m, key);
2680
  ck_assert_msg(res == 0, "Failed to remove list '%s': %s", key, strerror(errno));
1✔
2681

1✔
2682
  mark_point();
1✔
2683
  res = pr_redis_conn_destroy(redis);
1✔
2684
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2685
}
1✔
2686
END_TEST
1✔
2687

2688
START_TEST (redis_list_exists_test) {
1✔
2689
  int res;
1✔
2690
  pr_redis_t *redis;
1✔
2691
  module m;
1✔
2692
  const char *key;
2693
  char *val;
2694
  size_t valsz;
1✔
2695

1✔
2696
  mark_point();
1✔
2697
  res = pr_redis_list_exists(NULL, NULL, NULL, 0);
2698
  ck_assert_msg(res < 0, "Failed to handle null redis");
2699
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2700
    strerror(errno), errno);
1✔
2701

1✔
2702
  mark_point();
1✔
2703
  redis = pr_redis_conn_new(p, NULL, 0);
2704
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2705
    strerror(errno));
1✔
2706

1✔
2707
  mark_point();
1✔
2708
  res = pr_redis_list_exists(redis, NULL, NULL, 0);
1✔
2709
  ck_assert_msg(res < 0, "Failed to handle null module");
2710
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2711
    strerror(errno), errno);
1✔
2712

1✔
2713
  mark_point();
2714
  res = pr_redis_list_exists(redis, &m, NULL, 0);
1✔
2715
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2716
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2717
    strerror(errno), errno);
2718

1✔
2719
  key = "testkey";
1✔
2720
  (void) pr_redis_remove(redis, &m, key);
2721

1✔
2722
  mark_point();
1✔
2723
  res = pr_redis_list_exists(redis, &m, key, 0);
1✔
2724
  ck_assert_msg(res == FALSE, "Failed to handle nonexistent item");
2725

2726
  val = "testval";
1✔
2727
  valsz = strlen(val);
1✔
2728

1✔
2729
  mark_point();
2730
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
2731
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
2732
    strerror(errno));
1✔
2733

1✔
2734
  mark_point();
2735
  res = pr_redis_list_exists(redis, &m, key, 0);
2736
  ck_assert_msg(res == TRUE, "Failed to handle existing item");
1✔
2737

1✔
2738
  mark_point();
1✔
2739
  res = pr_redis_list_exists(redis, &m, key, 3);
2740
  ck_assert_msg(res < 0, "Failed to handle invalid index");
1✔
2741
  ck_assert_msg(errno == ERANGE, "Expected ERANGE (%d), got %s (%d)", ERANGE,
1✔
2742
    strerror(errno), errno);
1✔
2743

1✔
2744
  mark_point();
2745
  res = pr_redis_remove(redis, &m, key);
2746
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
2747

1✔
2748
  mark_point();
1✔
2749
  res = pr_redis_conn_destroy(redis);
1✔
2750
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2751
}
1✔
2752
END_TEST
1✔
2753

2754
START_TEST (redis_list_get_test) {
1✔
2755
  int res;
1✔
2756
  pr_redis_t *redis;
1✔
2757
  module m;
1✔
2758
  const char *key;
2759
  char *val;
2760
  size_t valsz;
1✔
2761

1✔
2762
  mark_point();
1✔
2763
  res = pr_redis_list_get(NULL, NULL, NULL, NULL, 0, NULL, NULL);
1✔
2764
  ck_assert_msg(res < 0, "Failed to handle null pool");
2765
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2766
    strerror(errno), errno);
1✔
2767

1✔
2768
  mark_point();
1✔
2769
  res = pr_redis_list_get(p, NULL, NULL, NULL, 0, NULL, NULL);
2770
  ck_assert_msg(res < 0, "Failed to handle null redis");
2771
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2772
    strerror(errno), errno);
1✔
2773

1✔
2774
  mark_point();
1✔
2775
  redis = pr_redis_conn_new(p, NULL, 0);
2776
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2777
    strerror(errno));
1✔
2778

1✔
2779
  mark_point();
1✔
2780
  res = pr_redis_list_get(p, redis, NULL, NULL, 0, NULL, NULL);
1✔
2781
  ck_assert_msg(res < 0, "Failed to handle null module");
2782
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2783
    strerror(errno), errno);
1✔
2784

1✔
2785
  mark_point();
2786
  res = pr_redis_list_get(p, redis, &m, NULL, 0, NULL, NULL);
1✔
2787
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2788
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2789
    strerror(errno), errno);
1✔
2790

2791
  key = "testkey";
2792
  (void) pr_redis_remove(redis, &m, key);
1✔
2793

1✔
2794
  mark_point();
1✔
2795
  res = pr_redis_list_get(p, redis, &m, key, 0, NULL, NULL);
1✔
2796
  ck_assert_msg(res < 0, "Failed to handle null value");
2797
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2798
    strerror(errno), errno);
1✔
2799

1✔
2800
  mark_point();
2801
  res = pr_redis_list_get(p, redis, &m, key, 0, (void **) &val, NULL);
1✔
2802
  ck_assert_msg(res < 0, "Failed to handle null valuesz");
1✔
2803
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2804
    strerror(errno), errno);
2805

2806
  val = "foo";
1✔
2807
  valsz = strlen(val);
1✔
2808

2809
  mark_point();
1✔
2810
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
2811
  ck_assert_msg(res == 0, "Failed to append item to key '%s': %s", key,
1✔
2812
    strerror(errno));
1✔
2813

2814
  val = NULL;
2815
  valsz = 0;
1✔
2816

1✔
2817
  mark_point();
1✔
2818
  res = pr_redis_list_get(p, redis, &m, key, 3, (void **) &val, &valsz);
1✔
2819
  ck_assert_msg(res < 0, "Failed to handle invalid index");
1✔
2820
  ck_assert_msg(errno == ERANGE, "Expected ERANGE (%d), got %s (%d)", ERANGE,
1✔
2821
    strerror(errno), errno);
2822

2823
  mark_point();
1✔
2824
  res = pr_redis_list_get(p, redis, &m, key, 0, (void **) &val, &valsz);
1✔
2825
  ck_assert_msg(res == 0, "Failed to get item in list: %s", strerror(errno));
1✔
2826
  ck_assert_msg(val != NULL, "Expected value, got null");
2827
  ck_assert_msg(valsz == 3, "Expected 3, got %lu", (unsigned long) valsz);
1✔
2828
  ck_assert_msg(memcmp(val, "foo", 3) == 0, "Expected 'foo', got '%.*s'",
1✔
2829
    (int) valsz, val);
1✔
2830

1✔
2831
  mark_point();
2832
  res = pr_redis_remove(redis, &m, key);
2833
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
2834

1✔
2835
  mark_point();
1✔
2836
  res = pr_redis_conn_destroy(redis);
1✔
2837
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2838
}
1✔
2839
END_TEST
1✔
2840

1✔
2841
START_TEST (redis_list_getall_test) {
2842
  int res;
1✔
2843
  pr_redis_t *redis;
1✔
2844
  module m;
1✔
2845
  const char *key;
1✔
2846
  char *val;
2847
  size_t valsz;
2848
  array_header *values = NULL, *valueszs = NULL;
1✔
2849

1✔
2850
  mark_point();
1✔
2851
  res = pr_redis_list_getall(NULL, NULL, NULL, NULL, NULL, NULL);
1✔
2852
  ck_assert_msg(res < 0, "Failed to handle null pool");
2853
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2854
    strerror(errno), errno);
1✔
2855

1✔
2856
  mark_point();
1✔
2857
  res = pr_redis_list_getall(p, NULL, NULL, NULL, NULL, NULL);
2858
  ck_assert_msg(res < 0, "Failed to handle null redis");
2859
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2860
    strerror(errno), errno);
1✔
2861

1✔
2862
  mark_point();
1✔
2863
  redis = pr_redis_conn_new(p, NULL, 0);
2864
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2865
    strerror(errno));
1✔
2866

1✔
2867
  mark_point();
1✔
2868
  res = pr_redis_list_getall(p, redis, NULL, NULL, NULL, NULL);
1✔
2869
  ck_assert_msg(res < 0, "Failed to handle null module");
2870
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2871
    strerror(errno), errno);
1✔
2872

1✔
2873
  mark_point();
2874
  res = pr_redis_list_getall(p, redis, &m, NULL, NULL, NULL);
1✔
2875
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2876
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2877
    strerror(errno), errno);
1✔
2878

2879
  key = "testkey";
2880
  (void) pr_redis_remove(redis, &m, key);
1✔
2881

1✔
2882
  mark_point();
1✔
2883
  res = pr_redis_list_getall(p, redis, &m, key, NULL, NULL);
1✔
2884
  ck_assert_msg(res < 0, "Failed to handle null values");
2885
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2886
    strerror(errno), errno);
1✔
2887

1✔
2888
  mark_point();
2889
  res = pr_redis_list_getall(p, redis, &m, key, &values, NULL);
1✔
2890
  ck_assert_msg(res < 0, "Failed to handle null valueszs");
1✔
2891
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2892
    strerror(errno), errno);
2893

2894
  val = "foo";
1✔
2895
  valsz = strlen(val);
1✔
2896

2897
  mark_point();
1✔
2898
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
2899
  ck_assert_msg(res == 0, "Failed to append item to key '%s': %s", key,
1✔
2900
    strerror(errno));
2901

2902
  val = "bar";
1✔
2903
  valsz = strlen(val);
1✔
2904

2905
  mark_point();
1✔
2906
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
2907
  ck_assert_msg(res == 0, "Failed to append item to key '%s': %s", key,
1✔
2908
    strerror(errno));
2909

2910
  val = "baz";
1✔
2911
  valsz = strlen(val);
1✔
2912

1✔
2913
  mark_point();
1✔
2914
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
2915
  ck_assert_msg(res == 0, "Failed to append item to key '%s': %s", key,
1✔
2916
    strerror(errno));
1✔
2917

2918
  mark_point();
1✔
2919
  res = pr_redis_list_getall(p, redis, &m, key, &values, &valueszs);
1✔
2920
  ck_assert_msg(res == 0, "Failed to get items in list: %s", strerror(errno));
1✔
2921
  ck_assert_msg(values != NULL, "Expected values, got null");
2922
  ck_assert_msg(valueszs != NULL, "Expected valueszs, got null");
1✔
2923
  ck_assert_msg(values->nelts == 3, "Expected 3, got %u", values->nelts);
1✔
2924
  ck_assert_msg(valueszs->nelts == 3, "Expected 3, got %u", valueszs->nelts);
1✔
2925

1✔
2926
  mark_point();
2927
  res = pr_redis_remove(redis, &m, key);
2928
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
2929

1✔
2930
  mark_point();
1✔
2931
  res = pr_redis_conn_destroy(redis);
1✔
2932
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2933
}
1✔
2934
END_TEST
1✔
2935

2936
START_TEST (redis_list_pop_params_test) {
1✔
2937
  int res;
1✔
2938
  pr_redis_t *redis;
1✔
2939
  module m;
1✔
2940
  const char *key;
2941
  char *val;
2942
  size_t valsz;
1✔
2943

1✔
2944
  mark_point();
1✔
2945
  res = pr_redis_list_pop(NULL, NULL, NULL, NULL, NULL, NULL, 0);
1✔
2946
  ck_assert_msg(res < 0, "Failed to handle null pool");
2947
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2948
    strerror(errno), errno);
1✔
2949

1✔
2950
  mark_point();
1✔
2951
  res = pr_redis_list_pop(p, NULL, NULL, NULL, NULL, NULL, 0);
2952
  ck_assert_msg(res < 0, "Failed to handle null redis");
2953
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2954
    strerror(errno), errno);
1✔
2955

1✔
2956
  mark_point();
1✔
2957
  redis = pr_redis_conn_new(p, NULL, 0);
2958
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
2959
    strerror(errno));
1✔
2960

1✔
2961
  mark_point();
1✔
2962
  res = pr_redis_list_pop(p, redis, NULL, NULL, NULL, NULL, 0);
1✔
2963
  ck_assert_msg(res < 0, "Failed to handle null module");
2964
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2965
    strerror(errno), errno);
1✔
2966

2967
  mark_point();
1✔
2968
  res = pr_redis_list_pop(p, redis, &m, NULL, NULL, NULL, 0);
1✔
2969
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
2970
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
2971
    strerror(errno), errno);
2972

2973
  key = "testkey";
1✔
2974

1✔
2975
  mark_point();
1✔
2976
  res = pr_redis_list_pop(p, redis, &m, key, NULL, NULL, 0);
1✔
2977
  ck_assert_msg(res < 0, "Failed to handle null value");
2978
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2979
    strerror(errno), errno);
1✔
2980

1✔
2981
  mark_point();
1✔
2982
  res = pr_redis_list_pop(p, redis, &m, key, (void **) &val, NULL, 0);
1✔
2983
  ck_assert_msg(res < 0, "Failed to handle null valuesz");
2984
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2985
    strerror(errno), errno);
1✔
2986

1✔
2987
  mark_point();
1✔
2988
  res = pr_redis_list_pop(p, redis, &m, key, (void **) &val, &valsz, 0);
1✔
2989
  ck_assert_msg(res < 0, "Failed to handle invalid flags");
2990
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
2991
    strerror(errno), errno);
1✔
2992

1✔
2993
  mark_point();
1✔
2994
  res = pr_redis_conn_destroy(redis);
1✔
2995
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
2996
}
1✔
2997
END_TEST
1✔
2998

2999
START_TEST (redis_list_pop_left_test) {
1✔
3000
  int res, flags = PR_REDIS_LIST_FL_LEFT;
1✔
3001
  pr_redis_t *redis;
1✔
3002
  module m;
3003
  const char *key;
3004
  char *val;
1✔
3005
  size_t valsz;
1✔
3006

3007
  mark_point();
1✔
3008
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
3009
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
3010
    strerror(errno));
1✔
3011

3012
  key = "testkey";
3013
  (void) pr_redis_remove(redis, &m, key);
1✔
3014

1✔
3015
  mark_point();
3016
  res = pr_redis_list_pop(p, redis, &m, key, (void **) &val, &valsz, flags);
1✔
3017
  ck_assert_msg(res < 0, "Failed to handle nonexistent list");
1✔
3018
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
3019
    strerror(errno), errno);
3020

3021
  val = "foo";
1✔
3022
  valsz = strlen(val);
1✔
3023

3024
  mark_point();
1✔
3025
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
3026
  ck_assert_msg(res == 0, "Failed to append item to key '%s': %s", key,
1✔
3027
    strerror(errno));
1✔
3028

1✔
3029
  val = NULL;
1✔
3030
  valsz = 0;
3031

3032
  mark_point();
1✔
3033
  res = pr_redis_list_pop(p, redis, &m, key, (void **) &val, &valsz, flags);
1✔
3034
  ck_assert_msg(res == 0, "Failed to get item in list: %s", strerror(errno));
1✔
3035
  ck_assert_msg(val != NULL, "Expected value, got null");
1✔
3036
  ck_assert_msg(valsz == 3, "Expected 3, got %lu", (unsigned long) valsz);
3037
  ck_assert_msg(memcmp(val, "foo", 3) == 0, "Expected 'foo', got '%.*s'",
3038
    (int) valsz, val);
1✔
3039

1✔
3040
  mark_point();
1✔
3041
  res = pr_redis_conn_destroy(redis);
1✔
3042
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3043
}
1✔
3044
END_TEST
1✔
3045

3046
START_TEST (redis_list_pop_right_test) {
1✔
3047
  int res, flags = PR_REDIS_LIST_FL_RIGHT;
1✔
3048
  pr_redis_t *redis;
1✔
3049
  module m;
3050
  const char *key;
3051
  char *val;
1✔
3052
  size_t valsz;
1✔
3053

3054
  mark_point();
1✔
3055
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
3056
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
1✔
3057
    strerror(errno));
1✔
3058

3059
  key = "testkey";
3060
  (void) pr_redis_remove(redis, &m, key);
1✔
3061

1✔
3062
  mark_point();
3063
  res = pr_redis_list_pop(p, redis, &m, key, (void **) &val, &valsz, flags);
1✔
3064
  ck_assert_msg(res < 0, "Failed to handle nonexistent list");
1✔
3065
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
3066
    strerror(errno), errno);
3067

3068
  val = "foo";
1✔
3069
  valsz = strlen(val);
1✔
3070

3071
  mark_point();
1✔
3072
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
3073
  ck_assert_msg(res == 0, "Failed to append item to key '%s': %s", key,
1✔
3074
    strerror(errno));
1✔
3075

1✔
3076
  val = NULL;
1✔
3077
  valsz = 0;
3078

3079
  mark_point();
1✔
3080
  res = pr_redis_list_pop(p, redis, &m, key, (void **) &val, &valsz, flags);
1✔
3081
  ck_assert_msg(res == 0, "Failed to get item in list: %s", strerror(errno));
1✔
3082
  ck_assert_msg(val != NULL, "Expected value, got null");
1✔
3083
  ck_assert_msg(valsz == 3, "Expected 3, got %lu", (unsigned long) valsz);
3084
  ck_assert_msg(memcmp(val, "foo", 3) == 0, "Expected 'foo', got '%.*s'",
3085
    (int) valsz, val);
1✔
3086

1✔
3087
  mark_point();
1✔
3088
  res = pr_redis_conn_destroy(redis);
1✔
3089
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3090
}
1✔
3091
END_TEST
1✔
3092

3093
START_TEST (redis_list_push_params_test) {
1✔
3094
  int res;
1✔
3095
  pr_redis_t *redis;
1✔
3096
  module m;
1✔
3097
  const char *key;
3098
  char *val;
3099
  size_t valsz;
1✔
3100

1✔
3101
  mark_point();
1✔
3102
  res = pr_redis_list_push(NULL, NULL, NULL, NULL, 0, 0);
3103
  ck_assert_msg(res < 0, "Failed to handle null redis");
3104
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3105
    strerror(errno), errno);
1✔
3106

1✔
3107
  mark_point();
1✔
3108
  redis = pr_redis_conn_new(p, NULL, 0);
3109
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3110
    strerror(errno));
1✔
3111

1✔
3112
  mark_point();
1✔
3113
  res = pr_redis_list_push(redis, NULL, NULL, NULL, 0, 0);
1✔
3114
  ck_assert_msg(res < 0, "Failed to handle null module");
3115
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3116
    strerror(errno), errno);
1✔
3117

3118
  mark_point();
1✔
3119
  res = pr_redis_list_push(redis, &m, NULL, NULL, 0, 0);
1✔
3120
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3121
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3122
    strerror(errno), errno);
3123

3124
  key = "testkey";
1✔
3125

1✔
3126
  mark_point();
3127
  res = pr_redis_list_push(redis, &m, key, NULL, 0, 0);
1✔
3128
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
3129
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3130
    strerror(errno), errno);
1✔
3131

3132
  val = "testval";
3133
  valsz = strlen(val);
1✔
3134

1✔
3135
  mark_point();
1✔
3136
  res = pr_redis_list_push(redis, &m, key, val, 0, 0);
1✔
3137
  ck_assert_msg(res < 0, "Failed to handle empty valuesz");
3138
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3139
    strerror(errno), errno);
1✔
3140

1✔
3141
  mark_point();
1✔
3142
  res = pr_redis_list_push(redis, &m, key, val, valsz, 0);
1✔
3143
  ck_assert_msg(res < 0, "Failed to handle invalid flags");
3144
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3145
    strerror(errno), errno);
1✔
3146

1✔
3147
  mark_point();
1✔
3148
  res = pr_redis_conn_destroy(redis);
1✔
3149
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3150
}
1✔
3151
END_TEST
1✔
3152

3153
START_TEST (redis_list_push_left_test) {
1✔
3154
  int res, flags = PR_REDIS_LIST_FL_LEFT;
1✔
3155
  pr_redis_t *redis;
1✔
3156
  module m;
3157
  const char *key;
3158
  char *val;
1✔
3159
  size_t valsz;
1✔
3160

3161
  mark_point();
1✔
3162
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
3163
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3164
    strerror(errno));
1✔
3165

1✔
3166
  key = "testlistkey";
1✔
3167
  (void) pr_redis_remove(redis, &m, key);
3168

3169
  val = "Some JSON here";
1✔
3170
  valsz = strlen(val);
1✔
3171

1✔
3172
  mark_point();
3173
  res = pr_redis_list_push(redis, &m, key, val, valsz, flags);
1✔
3174
  ck_assert_msg(res == 0, "Failed to append to list '%s': %s", key,
1✔
3175
    strerror(errno));
1✔
3176

1✔
3177
  mark_point();
3178
  res = pr_redis_list_remove(redis, &m, key);
3179
  ck_assert_msg(res == 0, "Failed to remove list '%s': %s", key, strerror(errno));
1✔
3180

1✔
3181
  mark_point();
1✔
3182
  res = pr_redis_conn_destroy(redis);
1✔
3183
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3184
}
1✔
3185
END_TEST
1✔
3186

3187
START_TEST (redis_list_push_right_test) {
1✔
3188
  int res, flags = PR_REDIS_LIST_FL_RIGHT;
1✔
3189
  pr_redis_t *redis;
1✔
3190
  module m;
3191
  const char *key;
3192
  char *val;
1✔
3193
  size_t valsz;
1✔
3194

3195
  mark_point();
1✔
3196
  redis = pr_redis_conn_new(p, NULL, 0);
1✔
3197
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3198
    strerror(errno));
1✔
3199

1✔
3200
  key = "testlistkey";
1✔
3201
  (void) pr_redis_remove(redis, &m, key);
3202

3203
  val = "Some JSON here";
1✔
3204
  valsz = strlen(val);
1✔
3205

1✔
3206
  mark_point();
3207
  res = pr_redis_list_push(redis, &m, key, val, valsz, flags);
1✔
3208
  ck_assert_msg(res == 0, "Failed to append to list '%s': %s", key,
1✔
3209
    strerror(errno));
1✔
3210

1✔
3211
  mark_point();
3212
  res = pr_redis_list_remove(redis, &m, key);
3213
  ck_assert_msg(res == 0, "Failed to remove list '%s': %s", key, strerror(errno));
1✔
3214

1✔
3215
  mark_point();
1✔
3216
  res = pr_redis_conn_destroy(redis);
1✔
3217
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3218
}
1✔
3219
END_TEST
1✔
3220

3221
START_TEST (redis_list_rotate_test) {
1✔
3222
  int res;
1✔
3223
  pr_redis_t *redis;
1✔
3224
  module m;
1✔
3225
  const char *key;
3226
  char *val = NULL;
3227
  size_t valsz = 0;
1✔
3228

1✔
3229
  mark_point();
1✔
3230
  res = pr_redis_list_rotate(NULL, NULL, NULL, NULL, NULL, NULL);
1✔
3231
  ck_assert_msg(res < 0, "Failed to handle null pool");
3232
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3233
    strerror(errno), errno);
1✔
3234

1✔
3235
  mark_point();
1✔
3236
  res = pr_redis_list_rotate(p, NULL, NULL, NULL, NULL, NULL);
3237
  ck_assert_msg(res < 0, "Failed to handle null redis");
3238
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3239
    strerror(errno), errno);
1✔
3240

1✔
3241
  mark_point();
1✔
3242
  redis = pr_redis_conn_new(p, NULL, 0);
3243
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3244
    strerror(errno));
1✔
3245

1✔
3246
  mark_point();
1✔
3247
  res = pr_redis_list_rotate(p, redis, NULL, NULL, NULL, NULL);
1✔
3248
  ck_assert_msg(res < 0, "Failed to handle null module");
3249
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3250
    strerror(errno), errno);
1✔
3251

1✔
3252
  mark_point();
3253
  res = pr_redis_list_rotate(p, redis, &m, NULL, NULL, NULL);
1✔
3254
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3255
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3256
    strerror(errno), errno);
1✔
3257

3258
  key = "testlistkey";
3259
  (void) pr_redis_remove(redis, &m, key);
1✔
3260

1✔
3261
  mark_point();
1✔
3262
  res = pr_redis_list_rotate(p, redis, &m, key, NULL, NULL);
1✔
3263
  ck_assert_msg(res < 0, "Failed to handle null value");
3264
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3265
    strerror(errno), errno);
1✔
3266

1✔
3267
  mark_point();
1✔
3268
  res = pr_redis_list_rotate(p, redis, &m, key, (void **) &val, NULL);
1✔
3269
  ck_assert_msg(res < 0, "Failed to handle null value");
3270
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3271
    strerror(errno), errno);
1✔
3272

1✔
3273
  mark_point();
3274
  res = pr_redis_list_rotate(p, redis, &m, key, (void **) &val, &valsz);
1✔
3275
  ck_assert_msg(res < 0, "Failed to handle nonexistent key");
1✔
3276
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
3277
    strerror(errno), errno);
3278

3279
  val = "foo";
1✔
3280
  valsz = strlen(val);
1✔
3281

3282
  mark_point();
1✔
3283
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
3284
  ck_assert_msg(res == 0, "Failed to append item using key '%s': %s", key,
1✔
3285
    strerror(errno));
3286

3287
  val = "bar";
1✔
3288
  valsz = strlen(val);
1✔
3289

3290
  mark_point();
1✔
3291
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
3292
  ck_assert_msg(res == 0, "Failed to append item using key '%s': %s", key,
1✔
3293
    strerror(errno));
1✔
3294

1✔
3295
  val = NULL;
1✔
3296
  valsz = 0;
3297

3298
  mark_point();
1✔
3299
  res = pr_redis_list_rotate(p, redis, &m, key, (void **) &val, &valsz);
1✔
3300
  ck_assert_msg(res == 0, "Failed to rotate list '%s': %s", key, strerror(errno));
3301
  ck_assert_msg(val != NULL, "Expected value, got NULL");
1✔
3302
  ck_assert_msg(valsz == 3, "Expected 3, got %lu", (unsigned long) valsz);
1✔
3303
  ck_assert_msg(memcmp(val, "bar", valsz) == 0, "Expected 'bar', got '%.*s'",
1✔
3304
    (int) valsz, val);
1✔
3305

1✔
3306
  val = NULL;
1✔
3307
  valsz = 0;
3308

3309
  mark_point();
1✔
3310
  res = pr_redis_list_rotate(p, redis, &m, key, (void **) &val, &valsz);
1✔
3311
  ck_assert_msg(res == 0, "Failed to rotate list '%s': %s", key, strerror(errno));
3312
  ck_assert_msg(val != NULL, "Expected value, got NULL");
1✔
3313
  ck_assert_msg(valsz == 3, "Expected 3, got %lu", (unsigned long) valsz);
1✔
3314
  ck_assert_msg(memcmp(val, "foo", valsz) == 0, "Expected 'foo', got '%.*s'",
1✔
3315
    (int) valsz, val);
1✔
3316

1✔
3317
  val = NULL;
1✔
3318
  valsz = 0;
3319

3320
  mark_point();
1✔
3321
  res = pr_redis_list_rotate(p, redis, &m, key, (void **) &val, &valsz);
1✔
3322
  ck_assert_msg(res == 0, "Failed to rotate list '%s': %s", key, strerror(errno));
1✔
3323
  ck_assert_msg(val != NULL, "Expected value, got NULL");
3324
  ck_assert_msg(valsz == 3, "Expected 3, got %lu", (unsigned long) valsz);
1✔
3325
  ck_assert_msg(memcmp(val, "bar", valsz) == 0, "Expected 'bar', got '%.*s'",
1✔
3326
    (int) valsz, val);
1✔
3327

1✔
3328
  mark_point();
3329
  res = pr_redis_list_remove(redis, &m, key);
3330
  ck_assert_msg(res == 0, "Failed to remove list '%s': %s", key, strerror(errno));
1✔
3331

1✔
3332
  mark_point();
1✔
3333
  res = pr_redis_conn_destroy(redis);
1✔
3334
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3335
}
1✔
3336
END_TEST
1✔
3337

3338
START_TEST (redis_list_set_test) {
1✔
3339
  int res;
1✔
3340
  pr_redis_t *redis;
1✔
3341
  module m;
1✔
3342
  const char *key;
3343
  char *val;
3344
  size_t valsz;
1✔
3345

1✔
3346
  mark_point();
1✔
3347
  res = pr_redis_list_set(NULL, NULL, NULL, 0, NULL, 0);
3348
  ck_assert_msg(res < 0, "Failed to handle null redis");
3349
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3350
    strerror(errno), errno);
1✔
3351

1✔
3352
  mark_point();
1✔
3353
  redis = pr_redis_conn_new(p, NULL, 0);
3354
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3355
    strerror(errno));
1✔
3356

1✔
3357
  mark_point();
1✔
3358
  res = pr_redis_list_set(redis, NULL, NULL, 0, NULL, 0);
1✔
3359
  ck_assert_msg(res < 0, "Failed to handle null module");
3360
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3361
    strerror(errno), errno);
1✔
3362

1✔
3363
  mark_point();
3364
  res = pr_redis_list_set(redis, &m, NULL, 0, NULL, 0);
1✔
3365
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3366
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3367
    strerror(errno), errno);
1✔
3368

3369
  key = "testlistkey";
3370
  (void) pr_redis_remove(redis, &m, key);
1✔
3371

3372
  mark_point();
1✔
3373
  res = pr_redis_list_set(redis, &m, key, 0, NULL, 0);
1✔
3374
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
3375
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3376
    strerror(errno), errno);
3377

3378
  val = "Some JSON here";
1✔
3379

3380
  mark_point();
1✔
3381
  res = pr_redis_list_set(redis, &m, key, 0, val, 0);
1✔
3382
  ck_assert_msg(res < 0, "Failed to handle empty value");
3383
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3384
    strerror(errno), errno);
1✔
3385

1✔
3386
  valsz = strlen(val);
1✔
3387

3388
  mark_point();
3389
  (void) pr_redis_list_remove(redis, &m, key);
1✔
3390

1✔
3391
  mark_point();
1✔
3392
  res = pr_redis_list_set(redis, &m, key, 3, val, valsz);
1✔
3393
  ck_assert_msg(res < 0, "Failed to handle invalid index");
3394
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3395
    strerror(errno), errno);
3396

3397
  mark_point();
1✔
3398
  res = pr_redis_list_set(redis, &m, key, 0, val, valsz);
1✔
3399
  ck_assert_msg(res < 0, "Failed to handle invalid index");
1✔
3400
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3401
    strerror(errno), errno);
3402

1✔
3403
  /* Append the item first, then set it. */
1✔
3404

3405
  mark_point();
1✔
3406
  res = pr_redis_list_append(redis, &m, key, val, valsz);
1✔
3407
  ck_assert_msg(res == 0, "Failed to append item using key '%s': %s", key,
1✔
3408
    strerror(errno));
3409

3410
  val = "listval2";
1✔
3411
  valsz = strlen(val);
1✔
3412

1✔
3413
  mark_point();
3414
  res = pr_redis_list_set(redis, &m, key, 0, val, valsz);
1✔
3415
  ck_assert_msg(res == 0, "Failed to set item at index 0 using key '%s': %s",
1✔
3416
    key, strerror(errno));
1✔
3417

1✔
3418
  mark_point();
3419
  res = pr_redis_list_remove(redis, &m, key);
3420
  ck_assert_msg(res == 0, "Failed to remove list '%s': %s", key, strerror(errno));
1✔
3421

1✔
3422
  mark_point();
1✔
3423
  res = pr_redis_conn_destroy(redis);
1✔
3424
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3425
}
1✔
3426
END_TEST
3427

1✔
3428
START_TEST (redis_list_setall_test) {
1✔
3429
  int res;
1✔
3430
  pr_redis_t *redis;
1✔
3431
  module m;
3432
  const char *key;
3433
  array_header *vals, *valszs;
1✔
3434

1✔
3435
  mark_point();
1✔
3436
  res = pr_redis_list_setall(NULL, NULL, NULL, NULL, NULL);
3437
  ck_assert_msg(res < 0, "Failed to handle null redis");
3438
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3439
    strerror(errno), errno);
1✔
3440

1✔
3441
  mark_point();
1✔
3442
  redis = pr_redis_conn_new(p, NULL, 0);
3443
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3444
    strerror(errno));
1✔
3445

1✔
3446
  mark_point();
1✔
3447
  res = pr_redis_list_setall(redis, NULL, NULL, NULL, NULL);
1✔
3448
  ck_assert_msg(res < 0, "Failed to handle null module");
3449
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3450
    strerror(errno), errno);
1✔
3451

1✔
3452
  mark_point();
3453
  res = pr_redis_list_setall(redis, &m, NULL, NULL, NULL);
1✔
3454
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3455
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3456
    strerror(errno), errno);
1✔
3457

3458
  key = "testlistkey";
3459
  (void) pr_redis_remove(redis, &m, key);
1✔
3460

3461
  mark_point();
1✔
3462
  res = pr_redis_list_setall(redis, &m, key, NULL, NULL);
1✔
3463
  ck_assert_msg(res < 0, "Failed to handle null values");
1✔
3464
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3465
    strerror(errno), errno);
3466

3467
  vals = make_array(p, 0, sizeof(char *));
1✔
3468

3469
  mark_point();
1✔
3470
  res = pr_redis_list_setall(redis, &m, key, vals, NULL);
1✔
3471
  ck_assert_msg(res < 0, "Failed to handle empty values");
1✔
3472
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3473
    strerror(errno), errno);
3474

3475
  *((char **) push_array(vals)) = pstrdup(p, "Some JSON here");
1✔
3476

3477
  mark_point();
1✔
3478
  res = pr_redis_list_setall(redis, &m, key, vals, NULL);
1✔
3479
  ck_assert_msg(res < 0, "Failed to handle null valueszs");
1✔
3480
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3481
    strerror(errno), errno);
3482

3483
  valszs = make_array(p, 0, sizeof(char *));
1✔
3484

1✔
3485
  mark_point();
3486
  res = pr_redis_list_setall(redis, &m, key, vals, valszs);
1✔
3487
  ck_assert_msg(res < 0, "Failed to handle empty valueszs");
1✔
3488
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3489
    strerror(errno), errno);
1✔
3490

3491
  *((size_t *) push_array(valszs)) = strlen("Some JSON here");
3492
  *((char **) push_array(vals)) = pstrdup(p, "bar");
1✔
3493

3494
  mark_point();
1✔
3495
  res = pr_redis_list_setall(redis, &m, key, vals, valszs);
1✔
3496
  ck_assert_msg(res < 0, "Failed to handle mismatched values/valueszs");
3497
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3498
    strerror(errno), errno);
1✔
3499

1✔
3500
  *((size_t *) push_array(valszs)) = strlen("bar");
3501

3502
  mark_point();
1✔
3503
  (void) pr_redis_list_remove(redis, &m, key);
1✔
3504

1✔
3505
  mark_point();
3506
  res = pr_redis_list_setall(redis, &m, key, vals, valszs);
1✔
3507
  ck_assert_msg(res == 0, "Failed to set items using key '%s': %s",
1✔
3508
    key, strerror(errno));
1✔
3509

1✔
3510
  mark_point();
3511
  res = pr_redis_list_remove(redis, &m, key);
3512
  ck_assert_msg(res == 0, "Failed to remove list '%s': %s", key, strerror(errno));
1✔
3513

1✔
3514
  mark_point();
1✔
3515
  res = pr_redis_conn_destroy(redis);
1✔
3516
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3517
}
3518
END_TEST
1✔
3519

1✔
3520
START_TEST (redis_set_remove_test) {
1✔
3521
  int res;
1✔
3522
  pr_redis_t *redis;
3523
  module m;
3524
  const char *key;
1✔
3525

1✔
3526
  mark_point();
1✔
3527
  res = pr_redis_set_remove(NULL, NULL, NULL);
3528
  ck_assert_msg(res < 0, "Failed to handle null redis");
3529
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3530
    strerror(errno), errno);
1✔
3531

1✔
3532
  mark_point();
1✔
3533
  redis = pr_redis_conn_new(p, NULL, 0);
3534
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3535
    strerror(errno));
1✔
3536

1✔
3537
  mark_point();
1✔
3538
  res = pr_redis_set_remove(redis, NULL, NULL);
1✔
3539
  ck_assert_msg(res < 0, "Failed to handle null module");
3540
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3541
    strerror(errno), errno);
1✔
3542

3543
  mark_point();
1✔
3544
  res = pr_redis_set_remove(redis, &m, NULL);
1✔
3545
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3546
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3547
    strerror(errno), errno);
3548

3549
  key = "testkey";
1✔
3550

1✔
3551
  mark_point();
1✔
3552
  res = pr_redis_set_remove(redis, &m, key);
1✔
3553
  ck_assert_msg(res < 0, "Unexpectedly removed key '%s'", key);
3554
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
3555
    strerror(errno), errno);
1✔
3556

1✔
3557
  mark_point();
1✔
3558
  res = pr_redis_conn_destroy(redis);
1✔
3559
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3560
}
1✔
3561
END_TEST
1✔
3562

3563
START_TEST (redis_set_exists_test) {
1✔
3564
  int res;
1✔
3565
  pr_redis_t *redis;
1✔
3566
  module m;
1✔
3567
  const char *key;
3568
  char *val;
3569
  size_t valsz;
1✔
3570

1✔
3571
  mark_point();
1✔
3572
  res = pr_redis_set_exists(NULL, NULL, NULL, NULL, 0);
3573
  ck_assert_msg(res < 0, "Failed to handle null redis");
3574
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3575
    strerror(errno), errno);
1✔
3576

1✔
3577
  mark_point();
1✔
3578
  redis = pr_redis_conn_new(p, NULL, 0);
3579
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3580
    strerror(errno));
1✔
3581

1✔
3582
  mark_point();
1✔
3583
  res = pr_redis_set_exists(redis, NULL, NULL, NULL, 0);
1✔
3584
  ck_assert_msg(res < 0, "Failed to handle null module");
3585
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3586
    strerror(errno), errno);
1✔
3587

1✔
3588
  mark_point();
3589
  res = pr_redis_set_exists(redis, &m, NULL, NULL, 0);
1✔
3590
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3591
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3592
    strerror(errno), errno);
1✔
3593

3594
  key = "testkey";
3595
  (void) pr_redis_remove(redis, &m, key);
1✔
3596

1✔
3597
  mark_point();
3598
  res = pr_redis_set_exists(redis, &m, key, NULL, 0);
1✔
3599
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
3600
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3601
    strerror(errno), errno);
1✔
3602

3603
  val = "testval";
3604
  valsz = 0;
1✔
3605

3606
  mark_point();
1✔
3607
  res = pr_redis_set_exists(redis, &m, key, val, valsz);
1✔
3608
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
3609
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3610
    strerror(errno), errno);
1✔
3611

1✔
3612
  valsz = strlen(val);
1✔
3613

3614
  mark_point();
3615
  res = pr_redis_set_exists(redis, &m, key, val, valsz);
1✔
3616
  ck_assert_msg(res == FALSE, "Failed to handle nonexistent item");
1✔
3617

1✔
3618
  mark_point();
3619
  res = pr_redis_set_add(redis, &m, key, val, valsz);
1✔
3620
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
3621
    strerror(errno));
1✔
3622

3623
  mark_point();
1✔
3624
  res = pr_redis_set_exists(redis, &m, key, val, valsz);
1✔
3625
  ck_assert_msg(res == TRUE, "Failed to handle existing item");
1✔
3626

1✔
3627
  mark_point();
3628
  res = pr_redis_set_remove(redis, &m, key);
3629
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
3630

1✔
3631
  mark_point();
1✔
3632
  res = pr_redis_conn_destroy(redis);
1✔
3633
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3634
}
1✔
3635
END_TEST
1✔
3636

3637
START_TEST (redis_set_add_test) {
1✔
3638
  int res;
1✔
3639
  pr_redis_t *redis;
1✔
3640
  module m;
1✔
3641
  const char *key;
3642
  char *val;
3643
  size_t valsz;
1✔
3644

1✔
3645
  mark_point();
1✔
3646
  res = pr_redis_set_add(NULL, NULL, NULL, NULL, 0);
3647
  ck_assert_msg(res < 0, "Failed to handle null redis");
3648
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3649
    strerror(errno), errno);
1✔
3650

1✔
3651
  mark_point();
1✔
3652
  redis = pr_redis_conn_new(p, NULL, 0);
3653
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3654
    strerror(errno));
1✔
3655

1✔
3656
  mark_point();
1✔
3657
  res = pr_redis_set_add(redis, NULL, NULL, NULL, 0);
1✔
3658
  ck_assert_msg(res < 0, "Failed to handle null module");
3659
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3660
    strerror(errno), errno);
1✔
3661

1✔
3662
  mark_point();
3663
  res = pr_redis_set_add(redis, &m, NULL, NULL, 0);
1✔
3664
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3665
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3666
    strerror(errno), errno);
1✔
3667

3668
  key = "testkey";
3669
  (void) pr_redis_set_remove(redis, &m, key);
1✔
3670

1✔
3671
  mark_point();
3672
  res = pr_redis_set_add(redis, &m, key, NULL, 0);
1✔
3673
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
3674
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3675
    strerror(errno), errno);
1✔
3676

3677
  val = "testval";
3678
  valsz = 0;
1✔
3679

3680
  mark_point();
1✔
3681
  res = pr_redis_set_add(redis, &m, key, val, 0);
1✔
3682
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
3683
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3684
    strerror(errno), errno);
3685

1✔
3686
  valsz = strlen(val);
1✔
3687

1✔
3688
  mark_point();
1✔
3689
  res = pr_redis_set_add(redis, &m, key, val, valsz);
3690
  ck_assert_msg(res == 0, "Failed to add key '%s', val '%s': %s", key, val,
3691
    strerror(errno));
1✔
3692

1✔
3693
  mark_point();
1✔
3694
  res = pr_redis_set_add(redis, &m, key, val, valsz);
3695
  ck_assert_msg(res < 0, "Failed to handle duplicates");
1✔
3696
  ck_assert_msg(errno == EEXIST, "Expected EEXIST (%d), got %s (%d)", EEXIST,
1✔
3697
    strerror(errno), errno);
1✔
3698

1✔
3699
  mark_point();
3700
  res = pr_redis_remove(redis, &m, key);
3701
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
3702

1✔
3703
  mark_point();
1✔
3704
  res = pr_redis_conn_destroy(redis);
1✔
3705
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3706
}
1✔
3707
END_TEST
1✔
3708

1✔
3709
START_TEST (redis_set_count_test) {
3710
  int res;
1✔
3711
  pr_redis_t *redis;
1✔
3712
  module m;
1✔
3713
  const char *key;
1✔
3714
  uint64_t count;
3715
  void *val;
3716
  size_t valsz;
1✔
3717

1✔
3718
  mark_point();
1✔
3719
  res = pr_redis_set_count(NULL, NULL, NULL, NULL);
3720
  ck_assert_msg(res < 0, "Failed to handle null redis");
3721
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3722
    strerror(errno), errno);
1✔
3723

1✔
3724
  mark_point();
1✔
3725
  redis = pr_redis_conn_new(p, NULL, 0);
3726
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3727
    strerror(errno));
1✔
3728

1✔
3729
  mark_point();
1✔
3730
  res = pr_redis_set_count(redis, NULL, NULL, NULL);
1✔
3731
  ck_assert_msg(res < 0, "Failed to handle null module");
3732
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3733
    strerror(errno), errno);
1✔
3734

3735
  mark_point();
1✔
3736
  res = pr_redis_set_count(redis, &m, NULL, NULL);
1✔
3737
  ck_assert_msg(res < 0, "Failed to handle null key");
3738
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3739
    strerror(errno), errno);
1✔
3740

1✔
3741
  mark_point();
1✔
3742

3743
  key = "testkey";
3744
  (void) pr_redis_remove(redis, &m, key);
1✔
3745

1✔
3746
  mark_point();
1✔
3747
  res = pr_redis_set_count(redis, &m, key, NULL);
1✔
3748
  ck_assert_msg(res < 0, "Failed to handle null count");
3749
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3750
    strerror(errno), errno);
1✔
3751

3752
  mark_point();
1✔
3753
  res = pr_redis_set_count(redis, &m, key, &count);
1✔
3754
  ck_assert_msg(res == 0, "Failed to handle get set count: %s", strerror(errno));
1✔
3755
  ck_assert_msg(count == 0, "Expected 0, got %lu", (unsigned long) count);
3756

3757
  val = "testval";
1✔
3758
  valsz = strlen(val);
1✔
3759

1✔
3760
  mark_point();
1✔
3761
  res = pr_redis_set_add(redis, &m, key, val, valsz);
3762
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
3763
    strerror(errno));
1✔
3764

1✔
3765
  mark_point();
3766
  res = pr_redis_set_count(redis, &m, key, &count);
1✔
3767
  ck_assert_msg(res == 0, "Failed to handle get set count: %s", strerror(errno));
1✔
3768
  ck_assert_msg(count == 1, "Expected 1, got %lu", (unsigned long) count);
1✔
3769

1✔
3770
  mark_point();
3771
  res = pr_redis_remove(redis, &m, key);
3772
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
3773

1✔
3774
  mark_point();
1✔
3775
  res = pr_redis_conn_destroy(redis);
1✔
3776
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3777
}
1✔
3778
END_TEST
1✔
3779

3780
START_TEST (redis_set_delete_test) {
1✔
3781
  int res;
1✔
3782
  pr_redis_t *redis;
1✔
3783
  module m;
1✔
3784
  const char *key;
3785
  char *val;
3786
  size_t valsz;
1✔
3787

1✔
3788
  mark_point();
1✔
3789
  res = pr_redis_set_delete(NULL, NULL, NULL, NULL, 0);
3790
  ck_assert_msg(res < 0, "Failed to handle null redis");
3791
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3792
    strerror(errno), errno);
1✔
3793

1✔
3794
  mark_point();
1✔
3795
  redis = pr_redis_conn_new(p, NULL, 0);
3796
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3797
    strerror(errno));
1✔
3798

1✔
3799
  mark_point();
1✔
3800
  res = pr_redis_set_delete(redis, NULL, NULL, NULL, 0);
1✔
3801
  ck_assert_msg(res < 0, "Failed to handle null module");
3802
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3803
    strerror(errno), errno);
1✔
3804

1✔
3805
  mark_point();
3806
  res = pr_redis_set_delete(redis, &m, NULL, NULL, 0);
1✔
3807
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3808
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3809
    strerror(errno), errno);
1✔
3810

3811
  key = "testkey";
3812
  (void) pr_redis_remove(redis, &m, key);
1✔
3813

1✔
3814
  mark_point();
3815
  res = pr_redis_set_delete(redis, &m, key, NULL, 0);
1✔
3816
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
3817
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3818
    strerror(errno), errno);
1✔
3819

3820
  val = "testval";
3821
  valsz = 0;
1✔
3822

3823
  mark_point();
1✔
3824
  res = pr_redis_set_delete(redis, &m, key, val, valsz);
1✔
3825
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
3826
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3827
    strerror(errno), errno);
3828

3829
  valsz = strlen(val);
1✔
3830

1✔
3831
  mark_point();
1✔
3832
  res = pr_redis_set_delete(redis, &m, key, val, valsz);
3833
  ck_assert_msg(res < 0, "Failed to handle nonexistent item");
3834
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
3835
    strerror(errno), errno);
1✔
3836

1✔
3837
  mark_point();
3838
  res = pr_redis_set_add(redis, &m, key, val, valsz);
3839
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
3840
    strerror(errno));
3841

3842
  mark_point();
1✔
3843
  res = pr_redis_set_delete(redis, &m, key, val, valsz);
1✔
3844
  ck_assert_msg(res == 0, "Failed to delete item from set: %s", strerror(errno));
1✔
3845

3846
  /* Note that we add this item back, just so that the set is NOT empty when
3847
   * we go to remove it entirely.
1✔
3848
   */
1✔
3849

1✔
3850
  mark_point();
3851
  res = pr_redis_set_add(redis, &m, key, val, valsz);
1✔
3852
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
3853
    strerror(errno));
1✔
3854

1✔
3855
  mark_point();
3856
  res = pr_redis_remove(redis, &m, key);
3857
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
3858

1✔
3859
  mark_point();
1✔
3860
  res = pr_redis_conn_destroy(redis);
1✔
3861
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3862
}
1✔
3863
END_TEST
1✔
3864

1✔
3865
START_TEST (redis_set_getall_test) {
3866
  int res;
1✔
3867
  pr_redis_t *redis;
1✔
3868
  module m;
1✔
3869
  const char *key;
1✔
3870
  char *val;
3871
  size_t valsz;
3872
  array_header *values = NULL, *valueszs = NULL;
1✔
3873

1✔
3874
  mark_point();
1✔
3875
  res = pr_redis_set_getall(NULL, NULL, NULL, NULL, NULL, NULL);
1✔
3876
  ck_assert_msg(res < 0, "Failed to handle null pool");
3877
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3878
    strerror(errno), errno);
1✔
3879

1✔
3880
  mark_point();
1✔
3881
  res = pr_redis_set_getall(p, NULL, NULL, NULL, NULL, NULL);
3882
  ck_assert_msg(res < 0, "Failed to handle null redis");
3883
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3884
    strerror(errno), errno);
1✔
3885

1✔
3886
  mark_point();
1✔
3887
  redis = pr_redis_conn_new(p, NULL, 0);
3888
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3889
    strerror(errno));
1✔
3890

1✔
3891
  mark_point();
1✔
3892
  res = pr_redis_set_getall(p, redis, NULL, NULL, NULL, NULL);
1✔
3893
  ck_assert_msg(res < 0, "Failed to handle null module");
3894
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3895
    strerror(errno), errno);
1✔
3896

1✔
3897
  mark_point();
3898
  res = pr_redis_set_getall(p, redis, &m, NULL, NULL, NULL);
1✔
3899
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3900
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3901
    strerror(errno), errno);
1✔
3902

3903
  key = "testkey";
3904
  (void) pr_redis_remove(redis, &m, key);
1✔
3905

1✔
3906
  mark_point();
1✔
3907
  res = pr_redis_set_getall(p, redis, &m, key, NULL, NULL);
1✔
3908
  ck_assert_msg(res < 0, "Failed to handle null values");
3909
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3910
    strerror(errno), errno);
1✔
3911

1✔
3912
  mark_point();
3913
  res = pr_redis_set_getall(p, redis, &m, key, &values, NULL);
1✔
3914
  ck_assert_msg(res < 0, "Failed to handle null valueszs");
1✔
3915
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3916
    strerror(errno), errno);
3917

3918
  val = "foo";
1✔
3919
  valsz = strlen(val);
1✔
3920

3921
  mark_point();
1✔
3922
  res = pr_redis_set_add(redis, &m, key, val, valsz);
1✔
3923
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
3924
    strerror(errno));
3925

3926
  val = "bar";
1✔
3927
  valsz = strlen(val);
1✔
3928

3929
  mark_point();
1✔
3930
  res = pr_redis_set_add(redis, &m, key, val, valsz);
1✔
3931
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
3932
    strerror(errno));
3933

3934
  val = "baz";
1✔
3935
  valsz = strlen(val);
1✔
3936

1✔
3937
  mark_point();
1✔
3938
  res = pr_redis_set_add(redis, &m, key, val, valsz);
1✔
3939
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
3940
    strerror(errno));
1✔
3941

3942
  mark_point();
1✔
3943
  res = pr_redis_set_getall(p, redis, &m, key, &values, &valueszs);
1✔
3944
  ck_assert_msg(res == 0, "Failed to get items in set: %s", strerror(errno));
1✔
3945
  ck_assert_msg(values != NULL, "Expected values, got null");
3946
  ck_assert_msg(valueszs != NULL, "Expected valueszs, got null");
1✔
3947
  ck_assert_msg(values->nelts == 3, "Expected 3, got %u", values->nelts);
1✔
3948
  ck_assert_msg(valueszs->nelts == 3, "Expected 3, got %u", valueszs->nelts);
1✔
3949

1✔
3950
  mark_point();
3951
  res = pr_redis_remove(redis, &m, key);
3952
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
3953

1✔
3954
  mark_point();
1✔
3955
  res = pr_redis_conn_destroy(redis);
1✔
3956
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
3957
}
1✔
3958
END_TEST
3959

1✔
3960
START_TEST (redis_set_setall_test) {
1✔
3961
  int res;
1✔
3962
  pr_redis_t *redis;
1✔
3963
  module m;
3964
  const char *key;
3965
  array_header *vals, *valszs;
1✔
3966

1✔
3967
  mark_point();
1✔
3968
  res = pr_redis_set_setall(NULL, NULL, NULL, NULL, NULL);
3969
  ck_assert_msg(res < 0, "Failed to handle null redis");
3970
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3971
    strerror(errno), errno);
1✔
3972

1✔
3973
  mark_point();
1✔
3974
  redis = pr_redis_conn_new(p, NULL, 0);
3975
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
3976
    strerror(errno));
1✔
3977

1✔
3978
  mark_point();
1✔
3979
  res = pr_redis_set_setall(redis, NULL, NULL, NULL, NULL);
1✔
3980
  ck_assert_msg(res < 0, "Failed to handle null module");
3981
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
3982
    strerror(errno), errno);
1✔
3983

1✔
3984
  mark_point();
3985
  res = pr_redis_set_setall(redis, &m, NULL, NULL, NULL);
1✔
3986
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
3987
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3988
    strerror(errno), errno);
1✔
3989

3990
  key = "testsetkey";
3991
  (void) pr_redis_remove(redis, &m, key);
1✔
3992

3993
  mark_point();
1✔
3994
  res = pr_redis_set_setall(redis, &m, key, NULL, NULL);
1✔
3995
  ck_assert_msg(res < 0, "Failed to handle null values");
1✔
3996
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
3997
    strerror(errno), errno);
3998

3999
  vals = make_array(p, 0, sizeof(char *));
1✔
4000

4001
  mark_point();
1✔
4002
  res = pr_redis_set_setall(redis, &m, key, vals, NULL);
1✔
4003
  ck_assert_msg(res < 0, "Failed to handle empty values");
1✔
4004
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4005
    strerror(errno), errno);
4006

4007
  *((char **) push_array(vals)) = pstrdup(p, "Some JSON here");
1✔
4008

4009
  mark_point();
1✔
4010
  res = pr_redis_set_setall(redis, &m, key, vals, NULL);
1✔
4011
  ck_assert_msg(res < 0, "Failed to handle null valueszs");
1✔
4012
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4013
    strerror(errno), errno);
4014

4015
  valszs = make_array(p, 0, sizeof(char *));
1✔
4016

1✔
4017
  mark_point();
4018
  res = pr_redis_set_setall(redis, &m, key, vals, valszs);
1✔
4019
  ck_assert_msg(res < 0, "Failed to handle empty valueszs");
1✔
4020
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4021
    strerror(errno), errno);
1✔
4022

4023
  *((size_t *) push_array(valszs)) = strlen("Some JSON here");
4024
  *((char **) push_array(vals)) = pstrdup(p, "bar");
1✔
4025

4026
  mark_point();
1✔
4027
  res = pr_redis_set_setall(redis, &m, key, vals, valszs);
1✔
4028
  ck_assert_msg(res < 0, "Failed to handle mismatched values/valueszs");
4029
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4030
    strerror(errno), errno);
1✔
4031

1✔
4032
  *((size_t *) push_array(valszs)) = strlen("bar");
4033

4034
  mark_point();
1✔
4035
  (void) pr_redis_set_remove(redis, &m, key);
1✔
4036

1✔
4037
  mark_point();
4038
  res = pr_redis_set_setall(redis, &m, key, vals, valszs);
1✔
4039
  ck_assert_msg(res == 0, "Failed to set items using key '%s': %s",
1✔
4040
    key, strerror(errno));
1✔
4041

1✔
4042
  mark_point();
4043
  res = pr_redis_set_remove(redis, &m, key);
4044
  ck_assert_msg(res == 0, "Failed to remove set '%s': %s", key, strerror(errno));
1✔
4045

1✔
4046
  mark_point();
1✔
4047
  res = pr_redis_conn_destroy(redis);
1✔
4048
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4049
}
4050
END_TEST
1✔
4051

1✔
4052
START_TEST (redis_sorted_set_remove_test) {
1✔
4053
  int res;
1✔
4054
  pr_redis_t *redis;
4055
  module m;
4056
  const char *key;
1✔
4057

1✔
4058
  mark_point();
1✔
4059
  res = pr_redis_sorted_set_remove(NULL, NULL, NULL);
4060
  ck_assert_msg(res < 0, "Failed to handle null redis");
4061
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4062
    strerror(errno), errno);
1✔
4063

1✔
4064
  mark_point();
1✔
4065
  redis = pr_redis_conn_new(p, NULL, 0);
4066
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4067
    strerror(errno));
1✔
4068

1✔
4069
  mark_point();
1✔
4070
  res = pr_redis_sorted_set_remove(redis, NULL, NULL);
1✔
4071
  ck_assert_msg(res < 0, "Failed to handle null module");
4072
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4073
    strerror(errno), errno);
1✔
4074

4075
  mark_point();
1✔
4076
  res = pr_redis_sorted_set_remove(redis, &m, NULL);
1✔
4077
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4078
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4079
    strerror(errno), errno);
4080

4081
  key = "testkey";
1✔
4082

1✔
4083
  mark_point();
1✔
4084
  res = pr_redis_sorted_set_remove(redis, &m, key);
1✔
4085
  ck_assert_msg(res < 0, "Unexpectedly removed key '%s'", key);
4086
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
4087
    strerror(errno), errno);
1✔
4088

1✔
4089
  mark_point();
1✔
4090
  res = pr_redis_conn_destroy(redis);
1✔
4091
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4092
}
1✔
4093
END_TEST
1✔
4094

4095
START_TEST (redis_sorted_set_exists_test) {
1✔
4096
  int res;
1✔
4097
  pr_redis_t *redis;
1✔
4098
  module m;
1✔
4099
  const char *key;
4100
  char *val;
4101
  size_t valsz;
1✔
4102

1✔
4103
  mark_point();
1✔
4104
  res = pr_redis_sorted_set_exists(NULL, NULL, NULL, NULL, 0);
4105
  ck_assert_msg(res < 0, "Failed to handle null redis");
4106
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4107
    strerror(errno), errno);
1✔
4108

1✔
4109
  mark_point();
1✔
4110
  redis = pr_redis_conn_new(p, NULL, 0);
4111
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4112
    strerror(errno));
1✔
4113

1✔
4114
  mark_point();
1✔
4115
  res = pr_redis_sorted_set_exists(redis, NULL, NULL, NULL, 0);
1✔
4116
  ck_assert_msg(res < 0, "Failed to handle null module");
4117
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4118
    strerror(errno), errno);
1✔
4119

1✔
4120
  mark_point();
4121
  res = pr_redis_sorted_set_exists(redis, &m, NULL, NULL, 0);
1✔
4122
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4123
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4124
    strerror(errno), errno);
1✔
4125

4126
  key = "testkey";
4127
  (void) pr_redis_remove(redis, &m, key);
1✔
4128

1✔
4129
  mark_point();
4130
  res = pr_redis_sorted_set_exists(redis, &m, key, NULL, 0);
1✔
4131
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
4132
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4133
    strerror(errno), errno);
1✔
4134

4135
  val = "testval";
4136
  valsz = 0;
1✔
4137

4138
  mark_point();
1✔
4139
  res = pr_redis_sorted_set_exists(redis, &m, key, val, valsz);
1✔
4140
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
4141
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4142
    strerror(errno), errno);
1✔
4143

1✔
4144
  valsz = strlen(val);
1✔
4145

4146
  mark_point();
4147
  res = pr_redis_sorted_set_exists(redis, &m, key, val, valsz);
1✔
4148
  ck_assert_msg(res == FALSE, "Failed to handle nonexistent item");
1✔
4149

1✔
4150
  mark_point();
4151
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, 1.0);
1✔
4152
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
4153
    strerror(errno));
1✔
4154

4155
  mark_point();
1✔
4156
  res = pr_redis_sorted_set_exists(redis, &m, key, val, valsz);
1✔
4157
  ck_assert_msg(res == TRUE, "Failed to handle existing item");
1✔
4158

1✔
4159
  mark_point();
4160
  res = pr_redis_sorted_set_remove(redis, &m, key);
4161
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4162

1✔
4163
  mark_point();
1✔
4164
  res = pr_redis_conn_destroy(redis);
1✔
4165
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4166
}
1✔
4167
END_TEST
1✔
4168

1✔
4169
START_TEST (redis_sorted_set_add_test) {
4170
  int res;
1✔
4171
  pr_redis_t *redis;
1✔
4172
  module m;
1✔
4173
  const char *key;
1✔
4174
  char *val;
4175
  size_t valsz;
4176
  float score;
1✔
4177

1✔
4178
  mark_point();
1✔
4179
  res = pr_redis_sorted_set_add(NULL, NULL, NULL, NULL, 0, 0.0);
4180
  ck_assert_msg(res < 0, "Failed to handle null redis");
4181
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4182
    strerror(errno), errno);
1✔
4183

1✔
4184
  mark_point();
1✔
4185
  redis = pr_redis_conn_new(p, NULL, 0);
4186
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4187
    strerror(errno));
1✔
4188

1✔
4189
  mark_point();
1✔
4190
  res = pr_redis_sorted_set_add(redis, NULL, NULL, NULL, 0, 0.0);
1✔
4191
  ck_assert_msg(res < 0, "Failed to handle null module");
4192
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4193
    strerror(errno), errno);
1✔
4194

1✔
4195
  mark_point();
4196
  res = pr_redis_sorted_set_add(redis, &m, NULL, NULL, 0, 0.0);
1✔
4197
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4198
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4199
    strerror(errno), errno);
1✔
4200

4201
  key = "testkey";
4202
  (void) pr_redis_remove(redis, &m, key);
1✔
4203

1✔
4204
  mark_point();
4205
  res = pr_redis_sorted_set_add(redis, &m, key, NULL, 0, 0.0);
1✔
4206
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
4207
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4208
    strerror(errno), errno);
1✔
4209

4210
  val = "testval";
4211
  valsz = 0;
1✔
4212

1✔
4213
  mark_point();
4214
  res = pr_redis_sorted_set_add(redis, &m, key, val, 0, 0.0);
1✔
4215
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
4216
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4217
    strerror(errno), errno);
4218

4219
  valsz = strlen(val);
1✔
4220
  score = 75.32;
1✔
4221

1✔
4222
  mark_point();
1✔
4223
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
4224
  ck_assert_msg(res == 0, "Failed to add key '%s', val '%s': %s", key, val,
4225
    strerror(errno));
1✔
4226

1✔
4227
  mark_point();
1✔
4228
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
4229
  ck_assert_msg(res < 0, "Failed to handle duplicates");
1✔
4230
  ck_assert_msg(errno == EEXIST, "Expected EEXIST (%d), got %s (%d)", EEXIST,
1✔
4231
    strerror(errno), errno);
1✔
4232

1✔
4233
  mark_point();
4234
  res = pr_redis_remove(redis, &m, key);
4235
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4236

1✔
4237
  mark_point();
1✔
4238
  res = pr_redis_conn_destroy(redis);
1✔
4239
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4240
}
1✔
4241
END_TEST
1✔
4242

1✔
4243
START_TEST (redis_sorted_set_count_test) {
1✔
4244
  int res;
4245
  pr_redis_t *redis;
1✔
4246
  module m;
1✔
4247
  const char *key;
1✔
4248
  uint64_t count;
1✔
4249
  void *val;
4250
  size_t valsz;
4251
  float score;
1✔
4252

1✔
4253
  mark_point();
1✔
4254
  res = pr_redis_sorted_set_count(NULL, NULL, NULL, NULL);
4255
  ck_assert_msg(res < 0, "Failed to handle null redis");
4256
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4257
    strerror(errno), errno);
1✔
4258

1✔
4259
  mark_point();
1✔
4260
  redis = pr_redis_conn_new(p, NULL, 0);
4261
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4262
    strerror(errno));
1✔
4263

1✔
4264
  mark_point();
1✔
4265
  res = pr_redis_sorted_set_count(redis, NULL, NULL, NULL);
1✔
4266
  ck_assert_msg(res < 0, "Failed to handle null module");
4267
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4268
    strerror(errno), errno);
1✔
4269

4270
  mark_point();
1✔
4271
  res = pr_redis_sorted_set_count(redis, &m, NULL, NULL);
1✔
4272
  ck_assert_msg(res < 0, "Failed to handle null key");
4273
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4274
    strerror(errno), errno);
1✔
4275

1✔
4276
  mark_point();
1✔
4277

4278
  key = "testkey";
4279
  (void) pr_redis_remove(redis, &m, key);
1✔
4280

1✔
4281
  mark_point();
1✔
4282
  res = pr_redis_sorted_set_count(redis, &m, key, NULL);
4283
  ck_assert_msg(res < 0, "Failed to handle null count");
1✔
4284
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4285
    strerror(errno), errno);
1✔
4286

1✔
4287
  mark_point();
1✔
4288
  res = pr_redis_sorted_set_count(redis, &m, key, &count);
4289
  ck_assert_msg(res == 0, "Failed to handle get sorted set count: %s",
1✔
4290
    strerror(errno));
1✔
4291
  ck_assert_msg(count == 0, "Expected 0, got %lu", (unsigned long) count);
1✔
4292

4293
  val = "testval";
4294
  valsz = strlen(val);
1✔
4295
  score = 23.45;
1✔
4296

1✔
4297
  mark_point();
1✔
4298
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
4299
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
4300
    strerror(errno));
1✔
4301

1✔
4302
  mark_point();
4303
  res = pr_redis_sorted_set_count(redis, &m, key, &count);
1✔
4304
  ck_assert_msg(res == 0, "Failed to handle get set count: %s", strerror(errno));
1✔
4305
  ck_assert_msg(count == 1, "Expected 1, got %lu", (unsigned long) count);
1✔
4306

1✔
4307
  mark_point();
4308
  res = pr_redis_remove(redis, &m, key);
4309
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4310

1✔
4311
  mark_point();
1✔
4312
  res = pr_redis_conn_destroy(redis);
1✔
4313
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4314
}
1✔
4315
END_TEST
1✔
4316

1✔
4317
START_TEST (redis_sorted_set_delete_test) {
4318
  int res;
1✔
4319
  pr_redis_t *redis;
1✔
4320
  module m;
1✔
4321
  const char *key;
1✔
4322
  char *val;
4323
  size_t valsz;
4324
  float score;
1✔
4325

1✔
4326
  mark_point();
1✔
4327
  res = pr_redis_sorted_set_delete(NULL, NULL, NULL, NULL, 0);
4328
  ck_assert_msg(res < 0, "Failed to handle null redis");
4329
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4330
    strerror(errno), errno);
1✔
4331

1✔
4332
  mark_point();
1✔
4333
  redis = pr_redis_conn_new(p, NULL, 0);
4334
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4335
    strerror(errno));
1✔
4336

1✔
4337
  mark_point();
1✔
4338
  res = pr_redis_sorted_set_delete(redis, NULL, NULL, NULL, 0);
1✔
4339
  ck_assert_msg(res < 0, "Failed to handle null module");
4340
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4341
    strerror(errno), errno);
1✔
4342

1✔
4343
  mark_point();
4344
  res = pr_redis_sorted_set_delete(redis, &m, NULL, NULL, 0);
1✔
4345
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4346
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4347
    strerror(errno), errno);
1✔
4348

4349
  key = "testkey";
4350
  (void) pr_redis_remove(redis, &m, key);
1✔
4351

1✔
4352
  mark_point();
4353
  res = pr_redis_sorted_set_delete(redis, &m, key, NULL, 0);
1✔
4354
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
4355
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4356
    strerror(errno), errno);
1✔
4357

4358
  val = "testval";
4359
  valsz = 0;
1✔
4360

4361
  mark_point();
1✔
4362
  res = pr_redis_sorted_set_delete(redis, &m, key, val, valsz);
1✔
4363
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
4364
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4365
    strerror(errno), errno);
4366

4367
  valsz = strlen(val);
1✔
4368

4369
  mark_point();
1✔
4370
  res = pr_redis_sorted_set_delete(redis, &m, key, val, valsz);
1✔
4371
  ck_assert_msg(res < 0, "Failed to handle nonexistent item");
1✔
4372
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
4373
    strerror(errno), errno);
4374

1✔
4375
  score = 1.23;
1✔
4376

1✔
4377
  mark_point();
4378
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
4379
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
4380
    strerror(errno));
4381

4382
  mark_point();
1✔
4383
  res = pr_redis_sorted_set_delete(redis, &m, key, val, valsz);
1✔
4384
  ck_assert_msg(res == 0, "Failed to delete item from set: %s", strerror(errno));
1✔
4385

4386
  /* Note that we add this item back, just so that the set is NOT empty when
4387
   * we go to remove it entirely.
1✔
4388
   */
1✔
4389

1✔
4390
  mark_point();
4391
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
1✔
4392
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
4393
    strerror(errno));
1✔
4394

1✔
4395
  mark_point();
4396
  res = pr_redis_remove(redis, &m, key);
4397
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4398

1✔
4399
  mark_point();
1✔
4400
  res = pr_redis_conn_destroy(redis);
1✔
4401
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4402
}
1✔
4403
END_TEST
1✔
4404

1✔
4405
START_TEST (redis_sorted_set_getn_test) {
1✔
4406
  int res;
4407
  pr_redis_t *redis;
1✔
4408
  module m;
1✔
4409
  const char *key;
1✔
4410
  char *val;
1✔
4411
  size_t valsz;
4412
  float score;
4413
  array_header *values = NULL, *valueszs = NULL;
1✔
4414

1✔
4415
  mark_point();
1✔
4416
  res = pr_redis_sorted_set_getn(NULL, NULL, NULL, NULL, 0, 0, NULL, NULL, 0);
1✔
4417
  ck_assert_msg(res < 0, "Failed to handle null pool");
4418
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4419
    strerror(errno), errno);
1✔
4420

1✔
4421
  mark_point();
1✔
4422
  res = pr_redis_sorted_set_getn(p, NULL, NULL, NULL, 0, 0, NULL, NULL, 0);
4423
  ck_assert_msg(res < 0, "Failed to handle null redis");
4424
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4425
    strerror(errno), errno);
1✔
4426

1✔
4427
  mark_point();
1✔
4428
  redis = pr_redis_conn_new(p, NULL, 0);
4429
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4430
    strerror(errno));
1✔
4431

1✔
4432
  mark_point();
1✔
4433
  res = pr_redis_sorted_set_getn(p, redis, NULL, NULL, 0, 0, NULL, NULL, 0);
1✔
4434
  ck_assert_msg(res < 0, "Failed to handle null module");
4435
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4436
    strerror(errno), errno);
1✔
4437

1✔
4438
  mark_point();
4439
  res = pr_redis_sorted_set_getn(p, redis, &m, NULL, 0, 0, NULL, NULL, 0);
1✔
4440
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4441
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4442
    strerror(errno), errno);
1✔
4443

4444
  key = "testkey";
4445
  (void) pr_redis_remove(redis, &m, key);
1✔
4446

1✔
4447
  mark_point();
1✔
4448
  res = pr_redis_sorted_set_getn(p, redis, &m, key, 0, 0, NULL, NULL, 0);
1✔
4449
  ck_assert_msg(res < 0, "Failed to handle null values");
4450
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4451
    strerror(errno), errno);
1✔
4452

1✔
4453
  mark_point();
4454
  res = pr_redis_sorted_set_getn(p, redis, &m, key, 0, 0, &values, NULL, 0);
1✔
4455
  ck_assert_msg(res < 0, "Failed to handle null valueszs");
1✔
4456
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4457
    strerror(errno), errno);
4458

1✔
4459
  mark_point();
1✔
4460
  res = pr_redis_sorted_set_getn(p, redis, &m, key, 0, 0, &values, &valueszs,
1✔
4461
    0);
4462
  ck_assert_msg(res < 0, "Failed to handle invalid flags value");
1✔
4463
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4464
    strerror(errno), errno);
1✔
4465

4466
  val = "foo";
4467
  valsz = strlen(val);
1✔
4468
  score = 0.123;
1✔
4469

1✔
4470
  mark_point();
4471
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
1✔
4472
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
4473
    strerror(errno));
1✔
4474

4475
  val = "bar";
4476
  valsz = strlen(val);
1✔
4477
  score = -1.56;
1✔
4478

1✔
4479
  mark_point();
4480
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
1✔
4481
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
4482
    strerror(errno));
1✔
4483

4484
  val = "baz";
4485
  valsz = strlen(val);
1✔
4486
  score = 234235.1;
1✔
4487

4488
  mark_point();
1✔
4489
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
4490
  ck_assert_msg(res == 0, "Failed to add item to key '%s': %s", key,
1✔
4491
    strerror(errno));
1✔
4492

1✔
4493
  mark_point();
1✔
4494
  res = pr_redis_sorted_set_getn(p, redis, &m, key, 0, 3, &values, &valueszs,
4495
    PR_REDIS_SORTED_SET_FL_DESC);
1✔
4496
  ck_assert_msg(res == 0, "Failed to get items in sorted set: %s",
1✔
4497
    strerror(errno));
4498
  ck_assert_msg(values != NULL, "Expected values, got null");
1✔
4499
  ck_assert_msg(valueszs != NULL, "Expected valueszs, got null");
4500
  ck_assert_msg(values->nelts == 3, "Expected 3, got %u", values->nelts);
1✔
4501
  ck_assert_msg(valueszs->nelts == 3, "Expected 3, got %u", valueszs->nelts);
1✔
4502

1✔
4503
  mark_point();
1✔
4504
  res = pr_redis_sorted_set_getn(p, redis, &m, key, 1, 2, &values, &valueszs,
4505
    PR_REDIS_SORTED_SET_FL_ASC);
1✔
4506
  ck_assert_msg(res == 0, "Failed to get items in sorted set: %s",
1✔
4507
    strerror(errno));
4508
  ck_assert_msg(values != NULL, "Expected values, got null");
1✔
4509
  ck_assert_msg(valueszs != NULL, "Expected valueszs, got null");
4510
  ck_assert_msg(values->nelts == 2, "Expected 2, got %u", values->nelts);
1✔
4511
  ck_assert_msg(valueszs->nelts == 2, "Expected 2, got %u", valueszs->nelts);
1✔
4512

1✔
4513
  mark_point();
1✔
4514
  res = pr_redis_sorted_set_getn(p, redis, &m, key, 1, 10, &values, &valueszs,
4515
    PR_REDIS_SORTED_SET_FL_ASC);
1✔
4516
  ck_assert_msg(res == 0, "Failed to get items in sorted set: %s",
1✔
4517
    strerror(errno));
1✔
4518
  ck_assert_msg(values != NULL, "Expected values, got null");
4519
  ck_assert_msg(valueszs != NULL, "Expected valueszs, got null");
1✔
4520
  ck_assert_msg(values->nelts == 2, "Expected 2, got %u", values->nelts);
1✔
4521
  ck_assert_msg(valueszs->nelts == 2, "Expected 2, got %u", valueszs->nelts);
1✔
4522

1✔
4523
  mark_point();
4524
  res = pr_redis_remove(redis, &m, key);
4525
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4526

1✔
4527
  mark_point();
1✔
4528
  res = pr_redis_conn_destroy(redis);
1✔
4529
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4530
}
1✔
4531
END_TEST
1✔
4532

1✔
4533
START_TEST (redis_sorted_set_incr_test) {
4534
  int res;
1✔
4535
  pr_redis_t *redis;
1✔
4536
  module m;
1✔
4537
  const char *key;
1✔
4538
  char *val;
4539
  size_t valsz;
4540
  float incr, curr;
1✔
4541

1✔
4542
  mark_point();
1✔
4543
  res = pr_redis_sorted_set_incr(NULL, NULL, NULL, NULL, 0, 0.0, NULL);
4544
  ck_assert_msg(res < 0, "Failed to handle null redis");
4545
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4546
    strerror(errno), errno);
1✔
4547

1✔
4548
  mark_point();
1✔
4549
  redis = pr_redis_conn_new(p, NULL, 0);
4550
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4551
    strerror(errno));
1✔
4552

1✔
4553
  mark_point();
1✔
4554
  res = pr_redis_sorted_set_incr(redis, NULL, NULL, NULL, 0, 0.0, NULL);
1✔
4555
  ck_assert_msg(res < 0, "Failed to handle null module");
4556
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4557
    strerror(errno), errno);
1✔
4558

1✔
4559
  mark_point();
4560
  res = pr_redis_sorted_set_incr(redis, &m, NULL, NULL, 0, 0.0, NULL);
1✔
4561
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4562
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4563
    strerror(errno), errno);
1✔
4564

4565
  key = "testval";
4566
  (void) pr_redis_remove(redis, &m, key);
1✔
4567

4568
  mark_point();
1✔
4569
  res = pr_redis_sorted_set_incr(redis, &m, key, NULL, 0, 0.0, NULL);
1✔
4570
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
4571
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4572
    strerror(errno), errno);
4573

4574
  val = "foo";
1✔
4575

1✔
4576
  mark_point();
4577
  res = pr_redis_sorted_set_incr(redis, &m, key, val, 0, 0.0, NULL);
1✔
4578
  ck_assert_msg(res < 0, "Failed to handle empty value");
1✔
4579
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4580
    strerror(errno), errno);
1✔
4581

4582
  valsz = strlen(val);
4583
  incr = 2.0;
1✔
4584

1✔
4585
  mark_point();
1✔
4586
  res = pr_redis_sorted_set_incr(redis, &m, key, val, valsz, incr, NULL);
1✔
4587
  ck_assert_msg(res < 0, "Failed to handle null current value");
4588
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4589
    strerror(errno), errno);
1✔
4590

1✔
4591
  mark_point();
1✔
4592
  res = pr_redis_sorted_set_incr(redis, &m, key, val, valsz, incr, &curr);
4593
  ck_assert_msg(res < 0, "Failed to handle nonexistent key");
4594
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
4595
    strerror(errno), errno);
1✔
4596

1✔
4597
  mark_point();
4598
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, incr);
4599
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
1✔
4600
    strerror(errno));
1✔
4601

1✔
4602
  mark_point();
4603
  res = pr_redis_sorted_set_incr(redis, &m, key, val, valsz, -incr, &curr);
1✔
4604
  ck_assert_msg(res == 0, "Failed to increment key '%s', val '%s': %s", key, val,
1✔
4605
    strerror(errno));
1✔
4606

1✔
4607
  mark_point();
4608
  res = pr_redis_remove(redis, &m, key);
4609
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4610

1✔
4611
  mark_point();
1✔
4612
  res = pr_redis_conn_destroy(redis);
1✔
4613
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4614
}
1✔
4615
END_TEST
1✔
4616

1✔
4617
START_TEST (redis_sorted_set_score_test) {
4618
  int res;
1✔
4619
  pr_redis_t *redis;
1✔
4620
  module m;
1✔
4621
  const char *key;
1✔
4622
  char *val;
4623
  size_t valsz;
4624
  float score;
1✔
4625

1✔
4626
  mark_point();
1✔
4627
  res = pr_redis_sorted_set_score(NULL, NULL, NULL, NULL, 0, NULL);
4628
  ck_assert_msg(res < 0, "Failed to handle null redis");
4629
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4630
    strerror(errno), errno);
1✔
4631

1✔
4632
  mark_point();
1✔
4633
  redis = pr_redis_conn_new(p, NULL, 0);
4634
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4635
    strerror(errno));
1✔
4636

1✔
4637
  mark_point();
1✔
4638
  res = pr_redis_sorted_set_score(redis, NULL, NULL, NULL, 0, NULL);
1✔
4639
  ck_assert_msg(res < 0, "Failed to handle null module");
4640
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4641
    strerror(errno), errno);
1✔
4642

1✔
4643
  mark_point();
4644
  res = pr_redis_sorted_set_score(redis, &m, NULL, NULL, 0, NULL);
1✔
4645
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4646
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4647
    strerror(errno), errno);
1✔
4648

4649
  key = "testval";
4650
  (void) pr_redis_remove(redis, &m, key);
1✔
4651

4652
  mark_point();
1✔
4653
  res = pr_redis_sorted_set_score(redis, &m, key, NULL, 0, NULL);
1✔
4654
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
4655
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4656
    strerror(errno), errno);
4657

4658
  val = "foo";
1✔
4659

4660
  mark_point();
1✔
4661
  res = pr_redis_sorted_set_score(redis, &m, key, val, 0, NULL);
1✔
4662
  ck_assert_msg(res < 0, "Failed to handle empty value");
1✔
4663
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4664
    strerror(errno), errno);
4665

4666
  valsz = strlen(val);
1✔
4667

1✔
4668
  mark_point();
1✔
4669
  res = pr_redis_sorted_set_score(redis, &m, key, val, valsz, NULL);
1✔
4670
  ck_assert_msg(res < 0, "Failed to handle null score");
4671
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4672
    strerror(errno), errno);
1✔
4673

1✔
4674
  mark_point();
1✔
4675
  res = pr_redis_sorted_set_score(redis, &m, key, val, valsz, &score);
4676
  ck_assert_msg(res < 0, "Failed to handle nonexistent key");
4677
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
4678
    strerror(errno), errno);
1✔
4679

1✔
4680
  mark_point();
4681
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, 1.0);
1✔
4682
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
4683
    strerror(errno));
1✔
4684

1✔
4685
  mark_point();
1✔
4686
  res = pr_redis_sorted_set_score(redis, &m, key, val, valsz, &score);
4687
  ck_assert_msg(res == 0, "Failed to score key '%s', val '%s': %s", key, val,
1✔
4688
    strerror(errno));
1✔
4689
  ck_assert_msg(score > 0.0, "Expected > 0.0, got %0.3f", score);
1✔
4690

1✔
4691
  mark_point();
4692
  res = pr_redis_remove(redis, &m, key);
4693
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4694

1✔
4695
  mark_point();
1✔
4696
  res = pr_redis_conn_destroy(redis);
1✔
4697
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4698
}
1✔
4699
END_TEST
1✔
4700

1✔
4701
START_TEST (redis_sorted_set_set_test) {
4702
  int res;
1✔
4703
  pr_redis_t *redis;
1✔
4704
  module m;
1✔
4705
  const char *key;
1✔
4706
  char *val;
4707
  size_t valsz;
4708
  float score;
1✔
4709

1✔
4710
  mark_point();
1✔
4711
  res = pr_redis_sorted_set_set(NULL, NULL, NULL, NULL, 0, 0.0);
4712
  ck_assert_msg(res < 0, "Failed to handle null redis");
4713
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4714
    strerror(errno), errno);
1✔
4715

1✔
4716
  mark_point();
1✔
4717
  redis = pr_redis_conn_new(p, NULL, 0);
4718
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4719
    strerror(errno));
1✔
4720

1✔
4721
  mark_point();
1✔
4722
  res = pr_redis_sorted_set_set(redis, NULL, NULL, NULL, 0, 0.0);
1✔
4723
  ck_assert_msg(res < 0, "Failed to handle null module");
4724
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4725
    strerror(errno), errno);
1✔
4726

1✔
4727
  mark_point();
4728
  res = pr_redis_sorted_set_set(redis, &m, NULL, NULL, 0, 0.0);
1✔
4729
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4730
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4731
    strerror(errno), errno);
1✔
4732

4733
  key = "testkey";
4734
  (void) pr_redis_remove(redis, &m, key);
1✔
4735

1✔
4736
  mark_point();
4737
  res = pr_redis_sorted_set_set(redis, &m, key, NULL, 0, 0.0);
1✔
4738
  ck_assert_msg(res < 0, "Failed to handle null value");
1✔
4739
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4740
    strerror(errno), errno);
1✔
4741

4742
  val = "testval";
4743
  valsz = 0;
1✔
4744

1✔
4745
  mark_point();
4746
  res = pr_redis_sorted_set_set(redis, &m, key, val, 0, 0.0);
1✔
4747
  ck_assert_msg(res < 0, "Failed to handle zero valuesz");
1✔
4748
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4749
    strerror(errno), errno);
1✔
4750

4751
  valsz = strlen(val);
4752
  score = 75.32;
1✔
4753

1✔
4754
  mark_point();
1✔
4755
  res = pr_redis_sorted_set_set(redis, &m, key, val, valsz, score);
4756
  ck_assert_msg(res < 0, "Failed to handle nonexistent key");
4757
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
1✔
4758
    strerror(errno), errno);
4759

1✔
4760
  mark_point();
1✔
4761
  res = pr_redis_sorted_set_add(redis, &m, key, val, valsz, score);
1✔
4762
  ck_assert_msg(res == 0, "Failed to add key '%s', val '%s': %s", key, val,
4763
    strerror(errno));
4764

1✔
4765
  score = 23.11;
1✔
4766

1✔
4767
  mark_point();
4768
  res = pr_redis_sorted_set_set(redis, &m, key, val, valsz, score);
1✔
4769
  ck_assert_msg(res == 0, "Failed to set key '%s', val '%s': %s", key, val,
1✔
4770
    strerror(errno));
1✔
4771

1✔
4772
  mark_point();
4773
  res = pr_redis_remove(redis, &m, key);
4774
  ck_assert_msg(res == 0, "Failed to remove key '%s': %s", key, strerror(errno));
1✔
4775

1✔
4776
  mark_point();
1✔
4777
  res = pr_redis_conn_destroy(redis);
1✔
4778
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
1✔
4779
}
1✔
4780
END_TEST
4781

1✔
4782
START_TEST (redis_sorted_set_setall_test) {
1✔
4783
  int res;
1✔
4784
  pr_redis_t *redis;
1✔
4785
  module m;
4786
  const char *key;
4787
  array_header *vals, *valszs, *scores;
1✔
4788

1✔
4789
  mark_point();
1✔
4790
  res = pr_redis_sorted_set_setall(NULL, NULL, NULL, NULL, NULL, NULL);
4791
  ck_assert_msg(res < 0, "Failed to handle null redis");
4792
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4793
    strerror(errno), errno);
1✔
4794

1✔
4795
  mark_point();
1✔
4796
  redis = pr_redis_conn_new(p, NULL, 0);
4797
  ck_assert_msg(redis != NULL, "Failed to open connection to Redis: %s",
4798
    strerror(errno));
1✔
4799

1✔
4800
  mark_point();
1✔
4801
  res = pr_redis_sorted_set_setall(redis, NULL, NULL, NULL, NULL, NULL);
1✔
4802
  ck_assert_msg(res < 0, "Failed to handle null module");
4803
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4804
    strerror(errno), errno);
1✔
4805

1✔
4806
  mark_point();
4807
  res = pr_redis_sorted_set_setall(redis, &m, NULL, NULL, NULL, NULL);
1✔
4808
  ck_assert_msg(res < 0, "Failed to handle null key");
1✔
4809
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4810
    strerror(errno), errno);
1✔
4811

4812
  key = "testsetkey";
4813
  (void) pr_redis_remove(redis, &m, key);
1✔
4814

4815
  mark_point();
1✔
4816
  res = pr_redis_sorted_set_setall(redis, &m, key, NULL, NULL, NULL);
1✔
4817
  ck_assert_msg(res < 0, "Failed to handle null values");
1✔
4818
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4819
    strerror(errno), errno);
4820

4821
  vals = make_array(p, 0, sizeof(char *));
1✔
4822

4823
  mark_point();
1✔
4824
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, NULL, NULL);
1✔
4825
  ck_assert_msg(res < 0, "Failed to handle empty values");
1✔
4826
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4827
    strerror(errno), errno);
4828

4829
  *((char **) push_array(vals)) = pstrdup(p, "Some JSON here");
1✔
4830

4831
  mark_point();
1✔
4832
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, NULL, NULL);
1✔
4833
  ck_assert_msg(res < 0, "Failed to handle null valueszs");
1✔
4834
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4835
    strerror(errno), errno);
4836

4837
  valszs = make_array(p, 0, sizeof(char *));
1✔
4838

1✔
4839
  mark_point();
4840
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, valszs, NULL);
1✔
4841
  ck_assert_msg(res < 0, "Failed to handle empty valueszs");
1✔
4842
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4843
    strerror(errno), errno);
1✔
4844

4845
  *((size_t *) push_array(valszs)) = strlen("Some JSON here");
4846
  *((char **) push_array(vals)) = pstrdup(p, "bar");
1✔
4847

4848
  mark_point();
1✔
4849
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, valszs, NULL);
1✔
4850
  ck_assert_msg(res < 0, "Failed to handle mismatched values/valueszs");
1✔
4851
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4852
    strerror(errno), errno);
4853

4854
  *((size_t *) push_array(valszs)) = strlen("bar");
1✔
4855

4856
  mark_point();
1✔
4857
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, valszs, NULL);
1✔
4858
  ck_assert_msg(res < 0, "Failed to handle null scores");
1✔
4859
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4860
    strerror(errno), errno);
4861

4862
  scores = make_array(p, 0, sizeof(char *));
1✔
4863

4864
  mark_point();
1✔
4865
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, valszs, scores);
1✔
4866
  ck_assert_msg(res < 0, "Failed to handle empty scores");
1✔
4867
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4868
    strerror(errno), errno);
4869

4870
  *((float *) push_array(scores)) = 1.0;
1✔
4871

4872
  mark_point();
1✔
4873
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, valszs, scores);
1✔
4874
  ck_assert_msg(res < 0, "Failed to handle mismatched values/scores");
4875
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
4876
    strerror(errno), errno);
1✔
4877

1✔
4878
  *((float *) push_array(scores)) = 2.0;
4879

4880
  mark_point();
1✔
4881
  (void) pr_redis_set_remove(redis, &m, key);
1✔
4882

1✔
4883
  mark_point();
4884
  res = pr_redis_sorted_set_setall(redis, &m, key, vals, valszs, scores);
1✔
4885
  ck_assert_msg(res == 0, "Failed to set items using key '%s': %s",
1✔
4886
    key, strerror(errno));
1✔
4887

1✔
4888
  mark_point();
4889
  res = pr_redis_set_remove(redis, &m, key);
4890
  ck_assert_msg(res == 0, "Failed to remove set '%s': %s", key, strerror(errno));
4891

4892
  mark_point();
890✔
4893
  res = pr_redis_conn_destroy(redis);
890✔
4894
  ck_assert_msg(res == TRUE, "Failed to close redis: %s", strerror(errno));
890✔
4895
}
4896
END_TEST
890✔
4897
#endif /* PR_USE_REDIS */
890✔
4898

4899
Suite *tests_get_redis_suite(void) {
4900
  Suite *suite;
890✔
4901
  TCase *testcase;
4902

890✔
4903
  suite = suite_create("redis");
890✔
4904
  testcase = tcase_create("base");
890✔
4905

890✔
4906
#if defined(PR_USE_REDIS)
890✔
4907
  tcase_add_checked_fixture(testcase, set_up, tear_down);
890✔
4908

890✔
4909
  tcase_add_test(testcase, redis_conn_destroy_test);
890✔
4910
  tcase_add_test(testcase, redis_conn_close_test);
890✔
4911
  tcase_add_test(testcase, redis_conn_new_test);
890✔
4912
  tcase_add_test(testcase, redis_conn_get_test);
890✔
4913
  tcase_add_test(testcase, redis_conn_set_namespace_test);
4914
  tcase_add_test(testcase, redis_conn_get_version_test);
890✔
4915
  tcase_add_test(testcase, redis_conn_auth_test);
890✔
4916
  tcase_add_test(testcase, redis_conn_auth2_test);
890✔
4917
  tcase_add_test(testcase, redis_conn_select_test);
4918
  tcase_add_test(testcase, redis_conn_reconnect_test);
890✔
4919
  tcase_add_test(testcase, redis_command_test);
890✔
4920

890✔
4921
  tcase_add_test(testcase, redis_sentinel_get_master_addr_test);
890✔
4922
  tcase_add_test(testcase, redis_sentinel_get_masters_test);
890✔
4923
  tcase_add_test(testcase, redis_sentinel_conn_new_test);
890✔
4924

890✔
4925
  tcase_add_test(testcase, redis_remove_test);
890✔
4926
  tcase_add_test(testcase, redis_add_test);
890✔
4927
  tcase_add_test(testcase, redis_add_with_namespace_test);
890✔
4928
  tcase_add_test(testcase, redis_get_test);
4929
  tcase_add_test(testcase, redis_get_with_namespace_test);
890✔
4930
  tcase_add_test(testcase, redis_get_str_test);
890✔
4931
  tcase_add_test(testcase, redis_incr_test);
890✔
4932
  tcase_add_test(testcase, redis_decr_test);
890✔
4933
  tcase_add_test(testcase, redis_rename_test);
890✔
4934
  tcase_add_test(testcase, redis_set_test);
890✔
4935

890✔
4936
  tcase_add_test(testcase, redis_hash_remove_test);
890✔
4937
  tcase_add_test(testcase, redis_hash_get_test);
890✔
4938
  tcase_add_test(testcase, redis_hash_set_test);
890✔
4939
  tcase_add_test(testcase, redis_hash_delete_test);
890✔
4940
  tcase_add_test(testcase, redis_hash_count_test);
4941
  tcase_add_test(testcase, redis_hash_exists_test);
890✔
4942
  tcase_add_test(testcase, redis_hash_incr_test);
890✔
4943
  tcase_add_test(testcase, redis_hash_keys_test);
890✔
4944
  tcase_add_test(testcase, redis_hash_values_test);
890✔
4945
  tcase_add_test(testcase, redis_hash_getall_test);
890✔
4946
  tcase_add_test(testcase, redis_hash_setall_test);
890✔
4947

890✔
4948
  tcase_add_test(testcase, redis_list_remove_test);
890✔
4949
  tcase_add_test(testcase, redis_list_append_test);
890✔
4950
  tcase_add_test(testcase, redis_list_count_test);
890✔
4951
  tcase_add_test(testcase, redis_list_delete_test);
890✔
4952
  tcase_add_test(testcase, redis_list_exists_test);
890✔
4953
  tcase_add_test(testcase, redis_list_get_test);
890✔
4954
  tcase_add_test(testcase, redis_list_getall_test);
890✔
4955
  tcase_add_test(testcase, redis_list_pop_params_test);
890✔
4956
  tcase_add_test(testcase, redis_list_pop_left_test);
890✔
4957
  tcase_add_test(testcase, redis_list_pop_right_test);
4958
  tcase_add_test(testcase, redis_list_push_params_test);
890✔
4959
  tcase_add_test(testcase, redis_list_push_left_test);
890✔
4960
  tcase_add_test(testcase, redis_list_push_right_test);
890✔
4961
  tcase_add_test(testcase, redis_list_rotate_test);
890✔
4962
  tcase_add_test(testcase, redis_list_set_test);
890✔
4963
  tcase_add_test(testcase, redis_list_setall_test);
890✔
4964

890✔
4965
  tcase_add_test(testcase, redis_set_remove_test);
4966
  tcase_add_test(testcase, redis_set_exists_test);
890✔
4967
  tcase_add_test(testcase, redis_set_add_test);
890✔
4968
  tcase_add_test(testcase, redis_set_count_test);
890✔
4969
  tcase_add_test(testcase, redis_set_delete_test);
890✔
4970
  tcase_add_test(testcase, redis_set_getall_test);
890✔
4971
  tcase_add_test(testcase, redis_set_setall_test);
890✔
4972

890✔
4973
  tcase_add_test(testcase, redis_sorted_set_remove_test);
890✔
4974
  tcase_add_test(testcase, redis_sorted_set_exists_test);
890✔
4975
  tcase_add_test(testcase, redis_sorted_set_add_test);
890✔
4976
  tcase_add_test(testcase, redis_sorted_set_count_test);
4977
  tcase_add_test(testcase, redis_sorted_set_delete_test);
4978
  tcase_add_test(testcase, redis_sorted_set_getn_test);
890✔
4979
  tcase_add_test(testcase, redis_sorted_set_incr_test);
4980
  tcase_add_test(testcase, redis_sorted_set_score_test);
4981
  tcase_add_test(testcase, redis_sorted_set_set_test);
890✔
4982
  tcase_add_test(testcase, redis_sorted_set_setall_test);
890✔
4983

4984
  /* Some of the Redis tests may take a little longer. */
4985
  tcase_set_timeout(testcase, 30);
4986
#endif /* PR_USE_REDIS */
4987

4988
  suite_add_tcase(suite, testcase);
4989
  return suite;
4990
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc