@@ -13,13 +13,56 @@ using json = nlohmann::json;
13
13
TEST (DBConnector, multi_db_test)
14
14
{
15
15
string file = " ./tests/redis_multi_db_ut_config/database_config.json" ;
16
+ string nonexisting_file = " ./tests/redis_multi_db_ut_config/database_config_nonexisting.json" ;
17
+
16
18
// by default , init should be false
17
19
cout<<" Default : isInit = " <<SonicDBConfig::isInit ()<<endl;
18
- EXPECT_EQ (SonicDBConfig::isInit (), false );
20
+ EXPECT_FALSE (SonicDBConfig::isInit ());
21
+
22
+
23
+ // load nonexisting file, should throw exception with NO file existing
24
+ try
25
+ {
26
+ cout<<" INIT: loading nonexisting db config file" <<endl;
27
+ SonicDBConfig::initialize (nonexisting_file);
28
+ }
29
+ catch (exception &e)
30
+ {
31
+ EXPECT_TRUE (strstr (e.what (), " Sonic database config file doesn't exist" ));
32
+ }
33
+ EXPECT_FALSE (SonicDBConfig::isInit ());
34
+
19
35
// load local config file, init should be true
20
36
SonicDBConfig::initialize (file);
21
- cout<<" INIT : load local db config file, isInit = " <<SonicDBConfig::isInit ()<<endl;
22
- EXPECT_EQ (SonicDBConfig::isInit (), true );
37
+ cout<<" INIT: load local db config file, isInit = " <<SonicDBConfig::isInit ()<<endl;
38
+ EXPECT_TRUE (SonicDBConfig::isInit ());
39
+
40
+ // load local config file again, should throw exception with init already done
41
+ try
42
+ {
43
+ cout<<" INIT: loading local config file again" <<endl;
44
+ SonicDBConfig::initialize (file);
45
+ }
46
+ catch (exception &e)
47
+ {
48
+ EXPECT_TRUE (strstr (e.what (), " SonicDBConfig already initialized" ));
49
+ }
50
+
51
+ // Invalid DB name input
52
+ cout<<" GET: invalid dbname input for getDbInst()" <<endl;
53
+ EXPECT_THROW (SonicDBConfig::getDbInst (" INVALID_DBNAME" ), out_of_range);
54
+
55
+ cout<<" GET: invalid dbname input for getDbId()" <<endl;
56
+ EXPECT_THROW (SonicDBConfig::getDbId (" INVALID_DBNAME" ), out_of_range);
57
+
58
+ cout<<" GET: invalid dbname input for getDbSock()" <<endl;
59
+ EXPECT_THROW (SonicDBConfig::getDbSock (" INVALID_DBNAME" ), out_of_range);
60
+
61
+ cout<<" GET: invalid dbname input for getDbHostname()" <<endl;
62
+ EXPECT_THROW (SonicDBConfig::getDbHostname (" INVALID_DBNAME" ), out_of_range);
63
+
64
+ cout<<" GET: invalid dbname input for getDbPort()" <<endl;
65
+ EXPECT_THROW (SonicDBConfig::getDbPort (" INVALID_DBNAME" ), out_of_range);
23
66
24
67
// parse config file
25
68
ifstream i (file);
0 commit comments