Skip to content

Commit 05cff79

Browse files
Add a unit test for connect_host.
1 parent d4a9cda commit 05cff79

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/test_redis_connect_host.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
import sys
3+
4+
if sys.version_info.major == 3:
5+
from unittest import mock
6+
else:
7+
import mock
8+
9+
modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10+
sys.path.insert(0, os.path.join(modules_path, 'src'))
11+
12+
from swsssdk import SonicV2Connector
13+
14+
def test_redis_connect_host():
15+
mock_dbintf = mock.MagicMock()
16+
db = SonicV2Connector()
17+
db.dbintf = mock_dbintf
18+
db.dbintf.redis_kwargs = {}
19+
20+
db_name = 'COUNTERS_DB'
21+
host = '127.0.0.1'
22+
23+
db.connect_host(db_name, host)
24+
mock_dbintf.connect.assert_called_once_with(2, db_name, True)
25+
26+
assert db.dbintf.redis_kwargs["host"] == host
27+
assert db.dbintf.redis_kwargs["port"] == 6379

0 commit comments

Comments
 (0)