dbx/tests/connectionUrlPlaceholder.te...

54 lines
2.3 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",
access: "jdbc:ucanaccess:///absolute/path/to/database.accdb",
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",
tdengine: "tdengine://user:password@host:6041/database",
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`);
}
});