fix(mysql): use database-specific catalog switching
This commit is contained in:
1 parent
9571519179
commit
2152f8cde8
31 files changed
+818
-182
No files matched your search
@@ -1,16 +1,30 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { databaseOptionsForConnection, fetchNamespaceOptionsForConnection, fetchSqlFileTargetOptions, namespaceOptionsAreSchemas, useDatabaseOptions } from "@/composables/useDatabaseOptions";
|
||||
import {
|
||||
databaseAfterCatalogChange,
|
||||
databaseOptionsForConnection,
|
||||
fetchNamespaceOptionsForConnection,
|
||||
fetchSqlFileTargetOptions,
|
||||
namespaceOptionsAreSchemas,
|
||||
normalizedQueryTabCatalog,
|
||||
queryCatalogSelectorVisible,
|
||||
selectedQueryCatalogName,
|
||||
useDatabaseOptions,
|
||||
} from "@/composables/useDatabaseOptions";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
ensureConnected: vi.fn(),
|
||||
getConfig: vi.fn(),
|
||||
listDatabases: vi.fn(),
|
||||
listSchemas: vi.fn(),
|
||||
listDorisCatalogs: vi.fn(),
|
||||
listDorisCatalogDatabases: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/backend/api", () => ({
|
||||
listDatabases: mocks.listDatabases,
|
||||
listSchemas: mocks.listSchemas,
|
||||
listDorisCatalogs: mocks.listDorisCatalogs,
|
||||
listDorisCatalogDatabases: mocks.listDorisCatalogDatabases,
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/connectionStore", () => ({
|
||||
@@ -20,6 +34,47 @@ vi.mock("@/stores/connectionStore", () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
const internalCatalog = { name: "default_catalog", catalog_type: "internal", is_current: true };
|
||||
const paimonCatalog = { name: "paimon_catalog", catalog_type: "paimon", is_current: false };
|
||||
|
||||
describe("query catalog options", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("shows the selector only when an external catalog exists", () => {
|
||||
expect(queryCatalogSelectorVisible([internalCatalog])).toBe(false);
|
||||
expect(queryCatalogSelectorVisible([internalCatalog, paimonCatalog])).toBe(true);
|
||||
});
|
||||
|
||||
it("maps the internal catalog to an undefined tab catalog", () => {
|
||||
const catalogs = [internalCatalog, paimonCatalog];
|
||||
|
||||
expect(selectedQueryCatalogName(catalogs)).toBe("default_catalog");
|
||||
expect(normalizedQueryTabCatalog(catalogs, "default_catalog")).toBeUndefined();
|
||||
expect(normalizedQueryTabCatalog(catalogs, "paimon_catalog")).toBe("paimon_catalog");
|
||||
});
|
||||
|
||||
it("keeps a database only when it exists in the selected catalog", () => {
|
||||
expect(databaseAfterCatalogChange("bi", ["bi", "default"])).toBe("bi");
|
||||
expect(databaseAfterCatalogChange("bi", ["analytics"])).toBe("");
|
||||
});
|
||||
|
||||
it("loads and caches catalog-scoped databases", async () => {
|
||||
mocks.getConfig.mockReturnValue({ db_type: "starrocks" });
|
||||
mocks.listDorisCatalogs.mockResolvedValue([internalCatalog, paimonCatalog]);
|
||||
mocks.listDorisCatalogDatabases.mockResolvedValue([{ name: "bi" }, { name: "analytics" }]);
|
||||
const options = useDatabaseOptions();
|
||||
|
||||
await expect(options.loadCatalogOptions("connection-1")).resolves.toEqual([internalCatalog, paimonCatalog]);
|
||||
await expect(options.loadCatalogDatabaseOptions("connection-1", "paimon_catalog")).resolves.toEqual(["bi", "analytics"]);
|
||||
await options.loadCatalogDatabaseOptions("connection-1", "paimon_catalog");
|
||||
|
||||
expect(options.catalogDatabaseOptions.value["connection-1:paimon_catalog"]).toEqual(["bi", "analytics"]);
|
||||
expect(mocks.listDorisCatalogDatabases).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("namespace options", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
Reference in new issue
Block a user