Skip to content

Commit

Permalink
Add unittest for ConfigDBConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
ericseifert committed May 30, 2023
1 parent 0f3e70d commit 621f9ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'redis>=4.5.4;python_version >= "3.0"',
'redis>=3.5.3;python_version < "3.0"',
'redis-dump-load',
'fakeredis',
]

high_performance_deps = [
Expand Down
31 changes: 31 additions & 0 deletions test/test_configdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import sys

from unittest import mock

from unittest import TestCase

modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(modules_path, 'src'))

import swsssdk
import fakeredis


class TestConfigDB(TestCase):
def test__configdb_pipe(self):

s_db = swsssdk.ConfigDBPipeConnector()
#Use fakeredis to mock redis db
r_db = fakeredis.FakeStrictRedis(version=5)
s_db.get_redis_client = lambda db_name: r_db
s_db.db_name = "CONFIG_DB"

s_db.mod_config({'TABLE_NAME': { 'row_key': {'column_key1': 'valueA1', 'column_key2': 'valueB1'}}})
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key1'), b'valueA1')
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key2'), b'valueB1')
s_db.mod_config({'TABLE_NAME': { 'row_key': {'column_key1': 'valueA2'}}}, table_delete='TABLE_NAME')
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key1'), b'valueA2')
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key2'), None)


0 comments on commit 621f9ab

Please sign in to comment.