Initial commit: add AutoDeploy project
This commit is contained in:
37
tests/test_service_console.py
Normal file
37
tests/test_service_console.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from deploy_tool.service_console import main
|
||||
|
||||
|
||||
class ServiceConsoleTests(unittest.TestCase):
|
||||
def test_tees_service_output_to_log_and_removes_pid_file(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
log_path = root / "service.log"
|
||||
pid_path = root / "service.pid"
|
||||
argv = [
|
||||
"service_console.py",
|
||||
"--log",
|
||||
str(log_path),
|
||||
"--pid-file",
|
||||
str(pid_path),
|
||||
"--",
|
||||
sys.executable,
|
||||
"-c",
|
||||
"print('service-ready')",
|
||||
]
|
||||
|
||||
with patch.object(sys, "argv", argv):
|
||||
exit_code = main()
|
||||
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertIn("service-ready", log_path.read_text(encoding="utf-8"))
|
||||
self.assertFalse(pid_path.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user