Handle missing Java service executable
This commit is contained in:
@@ -67,6 +67,30 @@ class ServiceConsoleTests(unittest.TestCase):
|
||||
self.assertIn("java-service-ready", log_path.read_text(encoding="utf-8"))
|
||||
self.assertFalse(pid_path.exists())
|
||||
|
||||
def test_missing_service_executable_is_logged_without_unhandled_exception(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
log_path = root / "service.log"
|
||||
pid_path = root / "service.pid"
|
||||
missing_executable = root / "missing-java.exe"
|
||||
argv = [
|
||||
"service_console.py",
|
||||
"--log",
|
||||
str(log_path),
|
||||
"--pid-file",
|
||||
str(pid_path),
|
||||
"--",
|
||||
str(missing_executable),
|
||||
"-version",
|
||||
]
|
||||
|
||||
with patch.object(sys, "argv", argv):
|
||||
exit_code = main()
|
||||
|
||||
self.assertEqual(exit_code, 1)
|
||||
self.assertIn("无法启动服务命令", log_path.read_text(encoding="utf-8"))
|
||||
self.assertFalse(pid_path.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user