1
1
/*
2
- * Copyright (C) 2018 OpenSIPS Solutions
2
+ * Copyright (C) 2018-2021 OpenSIPS Solutions
3
3
*
4
4
* This file is part of opensips, a free SIP server.
5
5
*
27
27
#include "../../sr_module.h"
28
28
#include "../../modparam.h"
29
29
30
+ #define CACHEDB_SKIP_BACKEND_TESTS
31
+
30
32
extern cachedb_engine * lookup_cachedb (str * name );
31
33
extern cachedb_con * cachedb_get_connection (cachedb_engine * cde ,str * group_name );
34
+ static void test_cachedb_backends (void );
35
+ static void load_cachedb_modules (void );
36
+ static void test_cachedb_url (void );
37
+
38
+
39
+ void init_cachedb_tests (void )
40
+ {
41
+ load_cachedb_modules ();
42
+ }
43
+
44
+
45
+ void test_cachedb (void )
46
+ {
47
+ test_cachedb_url ();
48
+ test_cachedb_backends ();
49
+ }
50
+
51
+
52
+ static void load_cachedb_modules (void )
53
+ {
54
+ #ifdef CACHEDB_SKIP_BACKEND_TESTS
55
+ return ;
56
+ #endif
57
+
58
+ if (load_module ("cachedb_mongodb.so" ) != 0 ) {
59
+ printf ("failed to load mongo\n" );
60
+ exit (-1 );
61
+ }
62
+
63
+ if (load_module ("cachedb_cassandra.so" ) != 0 ) {
64
+ printf ("failed to load cassandra\n" );
65
+ exit (-1 );
66
+ }
67
+
68
+ if (set_mod_param_regex ("cachedb_mongodb" , "cachedb_url" , STR_PARAM ,
69
+ "mongodb://10.0.0.177:27017/OpensipsTests.OpensipsTests" ) != 0 ) {
70
+ printf ("failed to set mongo url\n" );
71
+ exit (-1 );
72
+ }
73
+
74
+ if (set_mod_param_regex ("cachedb_cassandra" , "cachedb_url" , STR_PARAM ,
75
+ "cassandra:test1://10.0.0.178/testcass1.osstest1.osscnttest1" ) != 0 ) {
76
+ printf ("failed to set cassandra url\n" );
77
+ exit (-1 );
78
+ }
79
+
80
+ /* for Cassandra we need a different table schema for the col-oriented ops tests */
81
+ if (set_mod_param_regex ("cachedb_cassandra" , "cachedb_url" , STR_PARAM ,
82
+ "cassandra:test2://10.0.0.178/testcass1.osstest2.osscnttest1" ) != 0 ) {
83
+ printf ("failed to set cassandra url\n" );
84
+ exit (-1 );
85
+ }
86
+ }
87
+
32
88
33
89
int res_has_kv (const cdb_res_t * res , const cdb_pair_t * pair )
34
90
{
@@ -433,38 +489,6 @@ static void test_cachedb_api(const char *cachedb_name, const char *group1,
433
489
"column-oriented tests" );
434
490
}
435
491
436
- void init_cachedb_tests (void )
437
- {
438
- if (load_module ("cachedb_mongodb.so" ) != 0 ) {
439
- printf ("failed to load mongo\n" );
440
- exit (-1 );
441
- }
442
-
443
- if (load_module ("cachedb_cassandra.so" ) != 0 ) {
444
- printf ("failed to load cassandra\n" );
445
- exit (-1 );
446
- }
447
-
448
- if (set_mod_param_regex ("cachedb_mongodb" , "cachedb_url" , STR_PARAM ,
449
- "mongodb://10.0.0.177:27017/OpensipsTests.OpensipsTests" ) != 0 ) {
450
- printf ("failed to set mongo url\n" );
451
- exit (-1 );
452
- }
453
-
454
- if (set_mod_param_regex ("cachedb_cassandra" , "cachedb_url" , STR_PARAM ,
455
- "cassandra:test1://10.0.0.178/testcass1.osstest1.osscnttest1" ) != 0 ) {
456
- printf ("failed to set cassandra url\n" );
457
- exit (-1 );
458
- }
459
-
460
- /* for Cassandra we need a different table schema for the col-oriented ops tests */
461
- if (set_mod_param_regex ("cachedb_cassandra" , "cachedb_url" , STR_PARAM ,
462
- "cassandra:test2://10.0.0.178/testcass1.osstest2.osscnttest1" ) != 0 ) {
463
- printf ("failed to set cassandra url\n" );
464
- exit (-1 );
465
- }
466
- }
467
-
468
492
/*
469
493
* For Cassandra make sure to create the following tables:
470
494
* CREATE TABLE osstest1 (opensipskey text PRIMARY KEY, opensipsval text);
@@ -478,12 +502,54 @@ void init_cachedb_tests(void)
478
502
* );
479
503
*/
480
504
481
- void test_cachedb_backends (void )
505
+ static void test_cachedb_backends (void )
482
506
{
507
+ #ifdef CACHEDB_SKIP_BACKEND_TESTS
508
+ return ;
509
+ #endif
510
+
483
511
test_cachedb_api ("mongodb" , NULL , NULL );
484
512
test_cachedb_api ("cassandra" , "test1" , "test2" );
485
513
486
514
// todo();
487
515
// skip tests here
488
516
// end_todo;
489
517
}
518
+
519
+
520
+ static void test_cachedb_url (void )
521
+ {
522
+ struct cachedb_id * db ;
523
+
524
+ /* invalid URLs */
525
+ ok (!new_cachedb_id (_str ("d:g://@" )));
526
+ ok (!new_cachedb_id (_str ("d:g://u:@" )));
527
+ ok (!new_cachedb_id (_str ("d:g://u:p@" )));
528
+ ok (!new_cachedb_id (_str ("d:g://u:p@h" )));
529
+ ok (!new_cachedb_id (_str ("d:g://u:p@h:" )));
530
+
531
+ db = new_cachedb_id (
_str (
"redis:group1://:[email protected] :6379" ));
532
+ if (!ok (db != NULL ))
533
+ return ;
534
+ ok (str_match (_str (db -> scheme ), & str_init ("redis" )));
535
+ ok (str_match (_str (db -> group_name ), & str_init ("group1" )));
536
+ ok (str_match (_str (db -> username ), & str_init ("" )));
537
+ ok (str_match (_str (db -> password ), & str_init ("devxxxxxx" )));
538
+ ok (str_match (_str (db -> host ), & str_init ("172.31.180.127" )));
539
+ ok (db -> port == 6379 );
540
+ ok (!db -> database );
541
+ ok (!db -> extra_options );
542
+
543
+ db = new_cachedb_id (
_str (
"redis:group1://:[email protected] :6379/" ));
544
+ if (!ok (db != NULL ))
545
+ return ;
546
+ ok (db -> port == 6379 );
547
+ ok (!db -> database );
548
+ ok (!db -> extra_options );
549
+
550
+ db = new_cachedb_id (
_str (
"redis:group1://:[email protected] :6379/d?x=1&q=2" ));
551
+ if (!ok (db != NULL ))
552
+ return ;
553
+ ok (str_match (_str (db -> database ), & str_init ("d" )));
554
+ ok (str_match (_str (db -> extra_options ), & str_init ("x=1&q=2" )));
555
+ }
0 commit comments