39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from config import RuntimeSettings
|
|
from agent import cli
|
|
|
|
|
|
def _settings():
|
|
return RuntimeSettings(
|
|
node_name="n1",
|
|
log_path="/tmp/threat-agent.log",
|
|
state_file="/tmp/threat-agent-state.json",
|
|
check_interval=600,
|
|
check_jitter_pct=0.10,
|
|
heal_verify_delay=5,
|
|
heal_min_interval=900,
|
|
enforcement_targets=(("ip", "crowdsec"),),
|
|
enforcement_sets=(),
|
|
config_path="config.yaml",
|
|
)
|
|
|
|
|
|
class AgentCliTests(unittest.TestCase):
|
|
@patch("agent.load_runtime_settings", return_value=_settings())
|
|
@patch("agent.run_doctor", return_value=True)
|
|
def test_cli_doctor_returns_zero_on_success(self, _run_doctor, _settings_mock):
|
|
code = cli(["--doctor"])
|
|
self.assertEqual(0, code)
|
|
|
|
@patch("agent.main")
|
|
def test_cli_without_doctor_runs_main(self, main_mock):
|
|
code = cli([])
|
|
self.assertEqual(0, code)
|
|
main_mock.assert_called_once()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|