mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-29 16:18:55 +00:00
## 修改内容 - 新增 connectionUrlPlaceholder 纯函数于 connectionPresentation.ts,根据 db_type 返回对应 URL 格式 - ConnectionDialog.vue 中引用该函数替换原有统一的 i18n placeholder - 新增 20 个单元测试覆盖所有数据库类型及边界场景
52 lines
2.2 KiB
TypeScript
52 lines
2.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { connectionUrlPlaceholder } from "../src/lib/connectionPresentation.ts";
|
|
|
|
const expected: Record<string, string> = {
|
|
mysql: "mysql://user:password@host:port/database",
|
|
doris: "mysql://user:password@host:port/database",
|
|
starrocks: "mysql://user:password@host:port/database",
|
|
postgres: "postgresql://user:password@host:port/database",
|
|
gaussdb: "postgresql://user:password@host:port/database",
|
|
redshift: "postgresql://user:password@host:port/database",
|
|
redis: "redis://:password@host:port/0",
|
|
sqlite: "sqlite:///absolute/path/to/database.db",
|
|
duckdb: "duckdb:///absolute/path/to/database.duckdb",
|
|
mongodb: "mongodb://user:password@host:port/database",
|
|
clickhouse: "clickhouse://user:password@host:port/database",
|
|
sqlserver: "mssql://user:password@host:port/database",
|
|
oracle: "oracle://user:password@host:port/service_name",
|
|
elasticsearch: "http://user:password@host:port",
|
|
dameng: "dm://user:password@host:port",
|
|
jdbc: "jdbc:mysql://host:3306/database",
|
|
};
|
|
|
|
for (const [dbType, placeholder] of Object.entries(expected)) {
|
|
test(`returns correct placeholder for ${dbType}`, () => {
|
|
assert.equal(connectionUrlPlaceholder(dbType as any), placeholder);
|
|
});
|
|
}
|
|
|
|
test("falls back to postgresql placeholder for unknown type", () => {
|
|
assert.equal(connectionUrlPlaceholder("unknown" as any), "postgresql://user:password@host:port/database");
|
|
});
|
|
|
|
test("mysql-family types share the same placeholder", () => {
|
|
const mysql = connectionUrlPlaceholder("mysql");
|
|
assert.equal(connectionUrlPlaceholder("doris"), mysql);
|
|
assert.equal(connectionUrlPlaceholder("starrocks"), mysql);
|
|
});
|
|
|
|
test("postgres-family types share the same placeholder", () => {
|
|
const postgres = connectionUrlPlaceholder("postgres");
|
|
assert.equal(connectionUrlPlaceholder("gaussdb"), postgres);
|
|
assert.equal(connectionUrlPlaceholder("redshift"), postgres);
|
|
});
|
|
|
|
test("each placeholder starts with the expected scheme", () => {
|
|
for (const [dbType, placeholder] of Object.entries(expected)) {
|
|
const scheme = placeholder.split("://")[0];
|
|
assert.ok(scheme.length > 0, `${dbType} placeholder should have a scheme`);
|
|
}
|
|
});
|