Repair incomplete MySQL server setup

This commit is contained in:
王鹏
2026-10-09 11:00:40 +08:00
parent 7966b061c0
commit a2cf38f1a4
2 changed files with 66 additions and 17 deletions

View File

@@ -386,7 +386,9 @@ class InstallerTests(unittest.TestCase):
retry_delay=0,
)
self.assertEqual(run.call_count, 2)
self.assertEqual(run.call_count, 3)
self.assertEqual(run.call_args_list[1].kwargs["env"]["MYSQL_PWD"], MYSQL_ROOT_PASSWORD)
self.assertEqual(run.call_args_list[2].kwargs["env"]["MYSQL_PWD"], "")
def test_mysql_password_configuration_accepts_already_configured_password(self):
denied = CompletedProcess(
@@ -476,9 +478,23 @@ class InstallerTests(unittest.TestCase):
self.assertTrue(any("继续等待运行状态" in message for message in messages))
self.assertTrue(any("已启动" in message for message in messages))
def test_mysql_service_diagnostic_uses_server_executable(self):
mysql_client = Path(r"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe")
with (
patch("deploy_tool.installer.query_mysql_service_state", side_effect=[1, 4]),
patch("deploy_tool.installer.run_mysql_service_start_diagnostic", return_value=0) as diagnostic,
):
ensure_mysql_service_running(lambda _message: None, mysql_executable=mysql_client)
diagnostic.assert_called_once()
self.assertEqual(
diagnostic.call_args.kwargs["mysql_server_executable"],
mysql_client.with_name("mysqld.exe"),
)
def test_builds_privileged_mysql_service_start_diagnostic(self):
script = build_mysql_service_start_script(
mysql_executable=Path(r"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe")
mysql_server_executable=Path(r"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe")
)
self.assertIn("Start-Service -Name $name", script)
self.assertIn("Get-CimInstance Win32_Service", script)
@@ -487,6 +503,9 @@ class InstallerTests(unittest.TestCase):
self.assertIn("*.err", script)
self.assertIn("Get-Content", script)
self.assertIn("--validate-config", script)
self.assertIn("initialize-insecure", script)
self.assertIn("S-1-5-20", script)
self.assertIn("Service state after permission repair", script)
self.assertIn("Get-WinEvent", script)
self.assertIn("mysqld.exe", script)
@@ -518,7 +537,7 @@ class InstallerTests(unittest.TestCase):
exit_code = run_mysql_service_start_diagnostic(
"MySQL80",
log_path,
mysql_executable=Path("mysqld.exe"),
mysql_server_executable=Path("mysqld.exe"),
)
self.assertEqual(exit_code, 1)