Fix MySQL server installer invocation

This commit is contained in:
王鹏
2026-10-09 10:23:26 +08:00
parent d4efdd01b4
commit b73682412f
2 changed files with 103 additions and 7 deletions

View File

@@ -22,6 +22,8 @@ from deploy_tool.installer import (
build_mysql_server_install_command,
configure_mysql_weak_password_policy,
default_mysql_install_log_path,
default_mysql_server_install_log_path,
run_elevated_command_with_log,
TOMCAT_VERSION,
install_maven,
install_mysql,
@@ -200,10 +202,10 @@ class InstallerTests(unittest.TestCase):
def test_builds_tracked_mysql_server_console_command_with_strong_initial_password(self):
command = build_mysql_server_install_command(Path("MySQLInstallerConsole.exe"))
self.assertEqual(command[0:2], ["MySQLInstallerConsole.exe", "--install"])
self.assertIn("server;8.0.43;x64:*:", command[2])
self.assertIn(f"root_passwd={MYSQL_INITIAL_ROOT_PASSWORD}", command[2])
self.assertNotIn(f"root_passwd={MYSQL_ROOT_PASSWORD}", command[2])
self.assertEqual(command[0:3], ["MySQLInstallerConsole.exe", "community", "--install"])
self.assertIn("server;8.0.43;x64:*:", command[3])
self.assertIn(f"root_passwd={MYSQL_INITIAL_ROOT_PASSWORD}", command[3])
self.assertNotIn(f"root_passwd={MYSQL_ROOT_PASSWORD}", command[3])
self.assertIn("--silent", command)
self.assertIn("--auto-handle-prereqs", command)
@@ -250,7 +252,7 @@ class InstallerTests(unittest.TestCase):
self.assertIn("/passive", commands[0])
self.assertIn(str(install_log), commands[0])
self.assertEqual(commands[1][0], "MySQLInstallerConsole.exe")
self.assertEqual(commands[1][1], "--install")
self.assertEqual(commands[1][1:3], ["community", "--install"])
self.assertTrue(any("校验通过" in message for message in messages))
self.assertTrue(any("进度窗口" in message for message in messages))
self.assertTrue(any(str(install_log) in message for message in messages))
@@ -290,11 +292,37 @@ class InstallerTests(unittest.TestCase):
def test_uses_persistent_mysql_install_log_location(self):
with patch.dict("os.environ", {"LOCALAPPDATA": r"C:\Users\tester\AppData\Local"}):
log_path = default_mysql_install_log_path()
server_log_path = default_mysql_server_install_log_path()
self.assertEqual(
log_path,
Path(r"C:\Users\tester\AppData\Local") / "AutoDeploy" / "logs" / "mysql-install.log",
)
self.assertEqual(
server_log_path,
Path(r"C:\Users\tester\AppData\Local") / "AutoDeploy" / "logs" / "mysql-server-install.log",
)
def test_elevated_command_logging_uses_temporary_powershell_wrapper(self):
with tempfile.TemporaryDirectory() as tmp:
log_path = Path(tmp) / "mysql-server-install.log"
def inspect_wrapper(command, on_wait=None):
self.assertEqual(command[0], "powershell.exe")
script_path = Path(command[-1])
self.assertTrue(script_path.exists())
script = script_path.read_text(encoding="utf-8-sig")
self.assertIn("'community' '--install'", script)
self.assertIn(str(log_path), script)
return 2
with patch("deploy_tool.installer.run_elevated_command", side_effect=inspect_wrapper):
exit_code = run_elevated_command_with_log(
["MySQLInstallerConsole.exe", "community", "--install"],
log_path,
)
self.assertEqual(exit_code, 2)
def test_windows_elevation_dependency_is_imported(self):
self.assertIs(installer_module.ctypes, ctypes)