def test_run_protected_sys_exit(self, _, m_run, m_sys_exit): """Test failure in global method run_protected""" for exception_cls in (SystemExit, RuntimeError): _log.info("Testing that we handle %s exceptions", str(exception_cls.__name__)) m_run.side_effect = exception_cls with patch_object(sys, "argv", [None, "status", "ns/ns", "pod/pod", "id"]) as m_argv: calico_kubernetes.run_protected() # We should exit without error. m_sys_exit.assert_called_with(1)
def test_run_protected(self, m_mode, m_conf_logger, m_run, m_sys_exit): """Test global method run_protected Ensure code path not broken """ if m_mode == "init": patch_args = [None, m_mode] else: patch_args = [None, m_mode, "ns/ns", "pod/pod", "id"] with patch_object(sys, "argv", patch_args) as m_argv: calico_kubernetes.run_protected() # Check that the logger was set up; don't care about the details. assert_true(len(m_conf_logger.mock_calls) > 0) # Check we actually called the work function. if m_mode == "init": m_run.assert_called_with(mode=m_mode, namespace=None, pod_name=None, docker_id=None) else: m_run.assert_called_with(mode=m_mode, namespace="ns_ns", pod_name="pod_pod", docker_id="id") # We should exit without error. m_sys_exit.assert_called_with(0)