Skip to content

Commit

Permalink
Iproving coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rameshraghupathy committed Dec 13, 2024
1 parent 7a0d3d8 commit 1a55a59
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/process-reboot-cause_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,26 @@ def test_invalid_json(self, mock_geteuid, mock_stdout, mock_is_smartswitch, mock

# Check invalid JSON handling
output = mock_stdout.getvalue()
self.assertTrue(mock_connector.called)
self.assertTrue(mock_connector.called)

@patch("process_reboot_cause.swsscommon.SonicV2Connector")
@patch("process_reboot_cause.device_info.get_dpu_list", return_value=["dpu1", "dpu2"])
def test_update_dpu_reboot_cause_to_chassis_state_db(self, mock_get_dpu_list, mock_connector):
# Mock DB
mock_db = MagicMock()
mock_connector.return_value = mock_db

# Call the function
process_reboot_cause.update_dpu_reboot_cause_to_chassis_state_db()

# Verify DB interactions for each DPU
mock_db.set.assert_any_call(mock_db.CHASSIS_STATE_DB, "REBOOT_CAUSE|DPU1", "cause", "PowerLoss")
mock_db.set.assert_any_call(mock_db.CHASSIS_STATE_DB, "REBOOT_CAUSE|DPU1", "time", "2024-12-10")

@patch("process_reboot_cause.device_info.get_dpu_list", return_value=[])
def test_invalid_dpu_list(self, mock_get_dpu_list):
# Call the function with an empty DPU list
process_reboot_cause.update_dpu_reboot_cause_to_chassis_state_db()

# Ensure no DB interactions occur when DPU list is empty
mock_get_dpu_list.assert_called_once()

0 comments on commit 1a55a59

Please sign in to comment.