Skip to content

Commit

Permalink
update hostcfgd test file
Browse files Browse the repository at this point in the history
Signed-off-by: Arham-Nasir <arqamnasir719@gmail.com>
  • Loading branch information
Arham-Nasir committed Nov 16, 2024
1 parent 2d1704c commit de51001
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/hostcfgd/hostcfgd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,20 @@ def test_get_memory_statistics_pid_nonexistent(self, mock_pid_exists):
# mock_syslog.assert_any_call(mock.ANY,
# "MemoryStatisticsCfg: Exception failed to retrieve MemoryStatisticsDaemon PID: Unexpected error")

@mock.patch('hostcfgd.psutil.Process')
def test_get_memory_statistics_pid_exception(self, mock_process):
"""Test general exception handling in get_memory_statistics_pid"""
mock_process.side_effect = Exception("Unexpected error")
mock_open = mock.mock_open(read_data="123")

with mock.patch('hostcfgd.psutil.pid_exists', return_value=True):
with mock.patch('builtins.open', mock_open):
with mock.patch('hostcfgd.syslog.syslog') as mock_syslog:
pid = self.mem_stat_cfg.get_memory_statistics_pid()
self.assertIsNone(pid)
mock_syslog.assert_any_call(mock.ANY,
"MemoryStatisticsCfg: Exception failed to retrieve MemoryStatisticsDaemon PID: Unexpected error")

def test_memory_statistics_handler(self):
"""Test memory_statistics_handler in HostConfigDaemon"""
daemon = hostcfgd.HostConfigDaemon()
Expand Down

0 comments on commit de51001

Please sign in to comment.