|
1 | 1 | import assert from "node:assert/strict"; |
2 | | -import { mkdtemp, rm, writeFile } from "node:fs/promises"; |
| 2 | +import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; |
3 | 3 | import os from "node:os"; |
4 | 4 | import path from "node:path"; |
5 | 5 | import test from "node:test"; |
@@ -281,6 +281,74 @@ test("launches RDP connection files without endpoint fields", async () => { |
281 | 281 | assert.deepEqual(launchedPayload, payload); |
282 | 282 | }); |
283 | 283 |
|
| 284 | +for (const [platform, plugin, expected] of [ |
| 285 | + ["macos", "dbeaver", "driver=mysql"], |
| 286 | + ["linux", "dbeaver", "driver=mysql"], |
| 287 | + ["windows", "dbeaver", "driver=mysql"], |
| 288 | + ["windows", "navicat17", "navicat://conn.mysql?"], |
| 289 | + ["macos", "terminal-db", "mysql -u token-id"], |
| 290 | + ["linux", "terminal-db", "mysql -u token-id"], |
| 291 | + ["demo", "tablepro-uploadable", "mysql"] |
| 292 | +]) { |
| 293 | + test(`${platform}/${plugin} uses MySQL for MariaDB without changing application selection`, async () => { |
| 294 | + const directory = platform === "demo" ? plugin : `${platform}.${plugin}`; |
| 295 | + const config = JSON.parse( |
| 296 | + await readFile(path.join(projectRoot, "plugins", platform, directory, "connect.json"), "utf8") |
| 297 | + ); |
| 298 | + const application = { |
| 299 | + name: plugin, |
| 300 | + protocol: ["mariadb", "mysql"], |
| 301 | + is_set: true, |
| 302 | + // Only the MariaDB preference is enabled; normalization must happen after selection. |
| 303 | + enabled_protocols: ["mariadb"], |
| 304 | + match_first: ["mariadb"], |
| 305 | + launch_type: config.launch.type, |
| 306 | + launch_driver: config.launch.driver, |
| 307 | + arg_format: config.launch.template, |
| 308 | + protocol_templates: config.launch.protocol_templates |
| 309 | + }; |
| 310 | + const launcher = new LocalApplicationLauncher( |
| 311 | + { isPackaged: false }, |
| 312 | + projectRoot, |
| 313 | + { getConfig: async () => ({ databases: [application] }) }, |
| 314 | + null |
| 315 | + ); |
| 316 | + const payload = { |
| 317 | + protocol: "mariadb", |
| 318 | + name: "测试数据库", |
| 319 | + endpoint: { host: "gateway.example.com", port: 5525 }, |
| 320 | + token: { id: "token-id", value: "secret", protocol: "mariadb" }, |
| 321 | + asset: { info: { db_name: "app" } } |
| 322 | + }; |
| 323 | + let launches = 0; |
| 324 | + const checkArgs = async (selected, args) => { |
| 325 | + assert.equal(selected, application); |
| 326 | + assert.ok(args.includes(expected), args); |
| 327 | + assert.ok(args.includes("gateway.example.com"), args); |
| 328 | + assert.ok(args.includes("5525"), args); |
| 329 | + assert.ok(!args.includes("mariadb"), args); |
| 330 | + launches++; |
| 331 | + }; |
| 332 | + launcher.launchExecutable = checkArgs; |
| 333 | + launcher.launchTerminal = checkArgs; |
| 334 | + launcher.launchScript = async (selected, received, values) => { |
| 335 | + assert.equal(selected, application); |
| 336 | + assert.deepEqual(received, { ...payload, protocol: "mysql", ...(received.client ? { client: plugin } : {}) }); |
| 337 | + assert.equal(values.protocol, "mysql"); |
| 338 | + assert.equal(values.dbeaver_protocol, "mysql"); |
| 339 | + assert.equal(values.dbname, "app"); |
| 340 | + launches++; |
| 341 | + }; |
| 342 | + for (const client of [undefined, plugin]) { |
| 343 | + const url = `jms2://${Buffer.from(JSON.stringify({ ...payload, client })).toString("base64")}`; |
| 344 | + await launcher.launch(url); |
| 345 | + } |
| 346 | + assert.equal(launches, 2); |
| 347 | + assert.equal(payload.protocol, "mariadb"); |
| 348 | + assert.deepEqual(application.enabled_protocols, ["mariadb"]); |
| 349 | + }); |
| 350 | +} |
| 351 | + |
284 | 352 | test("normalizes duplicate and hidden system font families", () => { |
285 | 353 | assert.deepEqual(systemFontInternals.normalizeFamilies(["Menlo", " .Hidden ", "Menlo", "SF Mono", ""]), [ |
286 | 354 | "Menlo", |
|
0 commit comments