Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
  • Loading branch information
ZhaohuiS committed Dec 17, 2024
1 parent cb5e88b commit d6efce0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tests/caclmgrd/caclmgrd_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
import sys
import swsscommon
from unittest.mock import call
from unittest.mock import call, patch
from unittest import TestCase, mock
from tests.common.mock_configdb import MockConfigDb
from sonic_py_common.general import load_module_from_source
import threading
import time
import sys
import traceback

from queue import Queue
class TestCaclmgrd(TestCase):
def setUp(self):
Expand All @@ -34,3 +34,21 @@ def test_get_chain_list(self):
with mock.patch("caclmgrd.ControlPlaneAclManager.run_commands_pipe") as mock_run_commands_pipe:
caclmgrd_daemon.get_chain_list([], [''])
mock_run_commands_pipe.assert_has_calls(expected_calls)

@patch('caclmgrd.ControlPlaneAclManager.update_control_plane_acls')
def test_update_control_plane_acls_exception(self, mock_update):
# Set the side effect to raise an exception
mock_update.side_effect = Exception('Test exception')
# Mock the necessary attributes and methods
manager = self.caclmgrd.ControlPlaneAclManager("caclmgrd")
manager.UPDATE_DELAY_SECS = 1
manager.lock = {'': threading.Lock()}
manager.num_changes = {'': 0}
manager.update_thread = {'': None}
exception_queue = Queue()
manager.num_changes[''] = 1
manager.check_and_update_control_plane_acls('', 0, exception_queue)
self.assertFalse(exception_queue.empty())
exc_info = exception_queue.get()
self.assertEqual(exc_info[0], '')
self.assertIn('Test exception', exc_info[1])

0 comments on commit d6efce0

Please sign in to comment.