Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.9 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { buildPostgresForeignTableOptions, restorePostgresForeignTableDraft, supportsPostgresForeignTableCreation } from "../postgresForeignTable";

describe("PostgreSQL foreign table creation", () => {
  it("limits the creation form to native PostgreSQL profiles", () => {
    expect(supportsPostgresForeignTableCreation({ db_type: "postgres" })).toBe(true);
    expect(supportsPostgresForeignTableCreation({ db_type: "postgres", driver_profile: " POSTGRES " })).toBe(true);
    expect(supportsPostgresForeignTableCreation({ db_type: "postgres", driver_profile: "redshift" })).toBe(false);
    expect(supportsPostgresForeignTableCreation({ db_type: "mysql" })).toBe(false);
    expect(supportsPostgresForeignTableCreation()).toBe(false);
  });

  it("preserves exact server names and option values for backend quoting", () => {
    expect(
      buildPostgresForeignTableOptions({
        enabled: true,
        server: 'server" name',
        options: [
          { name: " schema_name ", value: "remote's schema" },
          { name: "", value: "" },
          { name: "filename", value: " path with spaces " },
        ],
      }),
    ).toEqual({
      server: 'server" name',
      options: [
        { name: "schema_name", value: "remote's schema" },
        { name: "filename", value: " path with spaces " },
      ],
    });
  });

  it("keeps invalid partial options for authoritative validation and clones restored drafts", () => {
    const saved = { enabled: true, server: "remote", options: [{ name: "", value: "orphan value" }] };
    const draft = restorePostgresForeignTableDraft(saved);
    expect(buildPostgresForeignTableOptions(draft).options).toEqual(saved.options);
    draft.options[0]!.value = "changed";
    expect(saved.options[0]!.value).toBe("orphan value");
    expect(restorePostgresForeignTableDraft()).toEqual({ enabled: false, server: "", options: [] });
  });
});