refactor(desktop): organize lib modules by domain
This commit is contained in:
1 parent
90f0594e93
commit
7e7c4944e9
700 files changed
+1292
-1264
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ACCESS_AGENT_MIN_CONNECT_TIMEOUT_SECS, AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS, connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs, CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS } from "@/lib/connection/connectionAttemptTimeout";
|
||||
|
||||
describe("connectionAttemptTimeout", () => {
|
||||
it("uses a 10s default for regular database connections", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "mysql", connect_timeout_secs: undefined, transport_layers: [] })).toBe(12_000);
|
||||
});
|
||||
|
||||
it("keeps explicit regular database timeout values", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "mysql", connect_timeout_secs: 5, transport_layers: [] })).toBe(7_000);
|
||||
});
|
||||
|
||||
it("uses a 30s agent startup floor", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "oracle", connect_timeout_secs: 5, transport_layers: [] })).toBe(AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
|
||||
});
|
||||
|
||||
it("uses the startup floor for PrestoSQL JDBC plugin connections", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "prestosql", connect_timeout_secs: 5, transport_layers: [] })).toBe(AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
|
||||
});
|
||||
|
||||
it("uses the startup floor for generic JDBC plugin connections", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "jdbc", connect_timeout_secs: 5, transport_layers: [] })).toBe(AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
|
||||
});
|
||||
|
||||
it("uses the startup floor for ZooKeeper agent connections", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "zookeeper", connect_timeout_secs: 5, transport_layers: [] })).toBe(AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
|
||||
});
|
||||
|
||||
it("uses a 30s Access agent startup floor", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "access", connect_timeout_secs: 5, transport_layers: [] })).toBe(ACCESS_AGENT_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
|
||||
});
|
||||
|
||||
it("respects a user configured Access timeout above the default floor", () => {
|
||||
expect(connectionAttemptTimeoutMs({ db_type: "access", connect_timeout_secs: 45, transport_layers: [] })).toBe(47_000);
|
||||
});
|
||||
|
||||
it("includes HTTP tunnel connection timeout values", () => {
|
||||
expect(
|
||||
connectionAttemptTimeoutMs({
|
||||
db_type: "mysql",
|
||||
connect_timeout_secs: 5,
|
||||
transport_layers: [
|
||||
{
|
||||
type: "http_tunnel",
|
||||
id: "http",
|
||||
url: "https://dbx.example.com/dbx_tunnel.php",
|
||||
connect_timeout_secs: 25,
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toBe(27_000);
|
||||
});
|
||||
|
||||
it("ignores disabled transport layer timeouts", () => {
|
||||
expect(
|
||||
connectionAttemptTimeoutMs({
|
||||
db_type: "mysql",
|
||||
connect_timeout_secs: 5,
|
||||
transport_layers: [
|
||||
{
|
||||
type: "http_tunnel",
|
||||
id: "http",
|
||||
enabled: false,
|
||||
url: "https://dbx.example.com/dbx_tunnel.php",
|
||||
connect_timeout_secs: 60,
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toBe(7_000);
|
||||
});
|
||||
|
||||
it("adds late original database errors to timeout messages", () => {
|
||||
const timeoutMessage = connectionAttemptTimeoutMessage(7_000);
|
||||
|
||||
expect(connectionAttemptOriginalErrorMessage(timeoutMessage, "MySQL connection failed: os error 10060")).toContain("MySQL connection failed: os error 10060");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { quickConnectionOpenTarget } from "@/lib/connection/connectionOpenTarget";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
function connection(dbType: ConnectionConfig["db_type"]): ConnectionConfig {
|
||||
return {
|
||||
id: "conn",
|
||||
name: "conn",
|
||||
db_type: dbType,
|
||||
host: "127.0.0.1",
|
||||
port: 0,
|
||||
user: "",
|
||||
password: "",
|
||||
database: "",
|
||||
readonly: false,
|
||||
read_only: false,
|
||||
ssl_mode: "disabled",
|
||||
color: "#888",
|
||||
} as ConnectionConfig;
|
||||
}
|
||||
|
||||
describe("quickConnectionOpenTarget", () => {
|
||||
it("opens message queue connections in the MQ admin console", () => {
|
||||
expect(quickConnectionOpenTarget(connection("mq"))).toEqual({ kind: "mq-admin" });
|
||||
});
|
||||
|
||||
it("opens Nacos connections in the Nacos admin console", () => {
|
||||
expect(quickConnectionOpenTarget(connection("nacos"))).toEqual({ kind: "nacos-admin" });
|
||||
});
|
||||
|
||||
it("opens regular connections in a query tab", () => {
|
||||
expect(quickConnectionOpenTarget({ ...connection("postgresql"), database: "app" })).toEqual({
|
||||
kind: "query",
|
||||
database: "app",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseConnectionUrl } from "@/lib/connection/connectionUrl";
|
||||
|
||||
describe("Dremio JDBC connection URLs", () => {
|
||||
it("parses legacy direct JDBC URLs into a Dremio JDBC profile", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:dremio:direct=dremio.example.com:31010;schema=analytics;user=admin;password=secret;ssl=true");
|
||||
|
||||
expect(parsed.dbType).toBe("jdbc");
|
||||
expect(parsed.driverProfile).toBe("dremio");
|
||||
expect(parsed.driverLabel).toBe("Dremio");
|
||||
expect(parsed.host).toBe("dremio.example.com");
|
||||
expect(parsed.port).toBe(31010);
|
||||
expect(parsed.database).toBe("analytics");
|
||||
expect(parsed.username).toBe("admin");
|
||||
expect(parsed.password).toBe("secret");
|
||||
expect(parsed.urlParams).toBe("ssl=true");
|
||||
expect(parsed.connectionString).toBe("jdbc:dremio:direct=dremio.example.com:31010;schema=analytics;user=admin;password=secret;ssl=true");
|
||||
});
|
||||
|
||||
it("uses the Dremio default port when the JDBC URL omits a port", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:dremio:direct=dremio.example.com");
|
||||
|
||||
expect(parsed.port).toBe(31010);
|
||||
expect(parsed.database).toBeUndefined();
|
||||
});
|
||||
|
||||
it("parses legacy ZooKeeper JDBC URLs into a Dremio JDBC profile", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:dremio:zk=zk.example.com;schema=analytics;tag=prod");
|
||||
|
||||
expect(parsed.dbType).toBe("jdbc");
|
||||
expect(parsed.driverProfile).toBe("dremio");
|
||||
expect(parsed.host).toBe("zk.example.com");
|
||||
expect(parsed.port).toBe(2181);
|
||||
expect(parsed.database).toBe("analytics");
|
||||
expect(parsed.urlParams).toBe("tag=prod");
|
||||
});
|
||||
|
||||
it("parses Arrow Flight SQL JDBC URLs into a Dremio JDBC profile", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:arrow-flight-sql://admin:secret@dremio.example.com:32010?schema=analytics&useEncryption=true");
|
||||
|
||||
expect(parsed.dbType).toBe("jdbc");
|
||||
expect(parsed.driverProfile).toBe("dremio");
|
||||
expect(parsed.driverLabel).toBe("Dremio");
|
||||
expect(parsed.host).toBe("dremio.example.com");
|
||||
expect(parsed.port).toBe(32010);
|
||||
expect(parsed.database).toBe("analytics");
|
||||
expect(parsed.username).toBe("admin");
|
||||
expect(parsed.password).toBe("secret");
|
||||
expect(parsed.urlParams).toBe("schema=analytics&useEncryption=true");
|
||||
expect(parsed.ssl).toBe(true);
|
||||
expect(parsed.connectionString).toBe("jdbc:arrow-flight-sql://admin:secret@dremio.example.com:32010?schema=analytics&useEncryption=true");
|
||||
});
|
||||
|
||||
it("uses the Arrow Flight SQL default port when the JDBC URL omits a port", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:arrow-flight-sql://dremio.example.com");
|
||||
|
||||
expect(parsed.port).toBe(32010);
|
||||
expect(parsed.database).toBeUndefined();
|
||||
});
|
||||
|
||||
it("parses unencrypted Arrow Flight SQL JDBC URLs", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:arrow-flight-sql://dremio.example.com:32010?useEncryption=false");
|
||||
|
||||
expect(parsed.port).toBe(32010);
|
||||
expect(parsed.urlParams).toBe("useEncryption=false");
|
||||
expect(parsed.ssl).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseConnectionUrl } from "@/lib/connection/connectionUrl";
|
||||
|
||||
describe("ZooKeeper connection URLs", () => {
|
||||
it("preserves the host:port chroot path as a ZooKeeper connect string", () => {
|
||||
expect(parseConnectionUrl("zookeeper://zk-main:2181/app").connectionString).toBe("zk-main:2181/app");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user