Skip to content

Commit

Permalink
update testcases
Browse files Browse the repository at this point in the history
Signed-off-by: Arham-Nasir <[email protected]>
  • Loading branch information
Arham-Nasir committed Nov 12, 2024
1 parent 4573619 commit d126612
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions tests/hostcfgd/hostcfgd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,28 +438,28 @@ def test_memory_statistics_update_invalid_configuration(self):
]
mocked_syslog.syslog.assert_has_calls(expected_logs)

def test_apply_memory_statistics_configuration(self):
with mock.patch('hostcfgd.subprocess') as mocked_subprocess:
popen_mock = mock.Mock()
attrs = {'communicate.return_value': ('output', 'error')}
popen_mock.configure_mock(**attrs)
mocked_subprocess.Popen.return_value = popen_mock

self.memorystatisticscfg.cache = {
"enabled": "true",
"sampling_interval": "10",
"retention_period": "30"
}
def test_apply_memory_statistics_configuration(self):
with mock.patch('hostcfgd.subprocess') as mocked_subprocess:
popen_mock = mock.Mock()
attrs = {'communicate.return_value': ('output', 'error')}
popen_mock.configure_mock(**attrs)
mocked_subprocess.Popen.return_value = popen_mock

self.memorystatisticscfg.cache = {
"enabled": "true",
"sampling_interval": "10",
"retention_period": "30"
}

# Apply each setting individually and check for the call
self.memorystatisticscfg.apply_setting("enabled", "true")
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])
# Apply each setting individually and check for the call
self.memorystatisticscfg.apply_setting("enabled", "true")
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])

self.memorystatisticscfg.apply_setting("sampling_interval", "10")
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])
self.memorystatisticscfg.apply_setting("sampling_interval", "10")
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])

self.memorystatisticscfg.apply_setting("retention_period", "30")
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])
self.memorystatisticscfg.apply_setting("retention_period", "30")
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])

def test_get_memory_statistics_pid(self):
with mock.patch('hostcfgd.psutil') as mocked_psutil:
Expand Down

0 comments on commit d126612

Please sign in to comment.