mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
test(connectors): cover required table listing
This commit is contained in:
parent
54dd9cc518
commit
4e4adcc061
4 changed files with 41 additions and 12 deletions
|
|
@ -15,8 +15,8 @@ function fakeClientFactory(): KtxClickHouseClientFactory {
|
|||
const query = vi.fn(async (input: { query: string; format: string; query_params?: Record<string, unknown> }) => {
|
||||
if (input.query.includes('FROM system.tables')) {
|
||||
return result([
|
||||
{ name: 'events', engine: 'MergeTree', comment: 'Event stream' },
|
||||
{ name: 'event_summary', engine: 'View', comment: '' },
|
||||
{ database: 'analytics', name: 'event_summary', engine: 'View', comment: '' },
|
||||
{ database: 'analytics', name: 'events', engine: 'MergeTree', comment: 'Event stream' },
|
||||
]);
|
||||
}
|
||||
if (input.query.includes('FROM system.columns')) {
|
||||
|
|
@ -223,8 +223,8 @@ describe('KtxClickHouseScanConnector', () => {
|
|||
},
|
||||
});
|
||||
expect(snapshot.tables.map((table) => [table.name, table.kind, table.estimatedRows, table.comment])).toEqual([
|
||||
['events', 'table', 2, 'Event stream'],
|
||||
['event_summary', 'view', null, null],
|
||||
['events', 'table', 2, 'Event stream'],
|
||||
]);
|
||||
expect(snapshot.tables.find((table) => table.name === 'events')?.columns[0]).toMatchObject({
|
||||
name: 'id',
|
||||
|
|
@ -371,6 +371,10 @@ describe('KtxClickHouseScanConnector', () => {
|
|||
|
||||
await expect(connector.getTableRowCount('events')).resolves.toBe(2);
|
||||
await expect(connector.listSchemas()).resolves.toEqual(['analytics', 'warehouse']);
|
||||
await expect(connector.listTables(['analytics'])).resolves.toEqual([
|
||||
{ schema: 'analytics', name: 'event_summary', kind: 'view' },
|
||||
{ schema: 'analytics', name: 'events', kind: 'table' },
|
||||
]);
|
||||
await expect(
|
||||
connector.columnStats(
|
||||
{ connectionId: 'warehouse', table: { catalog: null, db: 'analytics', name: 'events' }, column: 'event_name' },
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ function fakePoolFactory(): KtxMysqlPoolFactory {
|
|||
if (sql.includes('INFORMATION_SCHEMA.TABLES')) {
|
||||
return mysqlResult(
|
||||
[
|
||||
{ TABLE_NAME: 'customers', TABLE_TYPE: 'BASE TABLE', TABLE_COMMENT: 'Customer table', TABLE_ROWS: 2 },
|
||||
{ TABLE_NAME: 'orders', TABLE_TYPE: 'BASE TABLE', TABLE_COMMENT: 'InnoDB free: 1 kB; Order table', TABLE_ROWS: 2 },
|
||||
{ TABLE_NAME: 'order_summary', TABLE_TYPE: 'VIEW', TABLE_COMMENT: '', TABLE_ROWS: null },
|
||||
{ TABLE_SCHEMA: 'analytics', TABLE_NAME: 'customers', TABLE_TYPE: 'BASE TABLE', TABLE_COMMENT: 'Customer table', TABLE_ROWS: 2 },
|
||||
{ TABLE_SCHEMA: 'analytics', TABLE_NAME: 'orders', TABLE_TYPE: 'BASE TABLE', TABLE_COMMENT: 'InnoDB free: 1 kB; Order table', TABLE_ROWS: 2 },
|
||||
{ TABLE_SCHEMA: 'analytics', TABLE_NAME: 'order_summary', TABLE_TYPE: 'VIEW', TABLE_COMMENT: '', TABLE_ROWS: null },
|
||||
],
|
||||
[{ name: 'TABLE_NAME' }, { name: 'TABLE_TYPE' }, { name: 'TABLE_COMMENT' }, { name: 'TABLE_ROWS' }],
|
||||
);
|
||||
|
|
@ -510,6 +510,11 @@ describe('KtxMysqlScanConnector', () => {
|
|||
|
||||
await expect(connector.getTableRowCount('orders')).resolves.toBe(2);
|
||||
await expect(connector.listSchemas()).resolves.toEqual(['analytics', 'warehouse']);
|
||||
await expect(connector.listTables(['analytics'])).resolves.toEqual([
|
||||
{ schema: 'analytics', name: 'customers', kind: 'table' },
|
||||
{ schema: 'analytics', name: 'orders', kind: 'table' },
|
||||
{ schema: 'analytics', name: 'order_summary', kind: 'view' },
|
||||
]);
|
||||
await expect(connector.columnStats(
|
||||
{ connectionId: 'warehouse', table: { catalog: null, db: 'analytics', name: 'orders' }, column: 'status' },
|
||||
{ runId: 'scan-run-1' },
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ function metadataResults(): Map<string, FakeQueryResponse> {
|
|||
'FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n',
|
||||
{
|
||||
rows: [
|
||||
{ table_name: 'customers', table_kind: 'r', row_count: '2', table_comment: 'Customers' },
|
||||
{ table_name: 'orders', table_kind: 'r', row_count: '3', table_comment: null },
|
||||
{ table_name: 'recent_orders', table_kind: 'v', row_count: '0', table_comment: 'Recent orders' },
|
||||
{ schema_name: 'public', table_name: 'customers', table_kind: 'r', row_count: '2', table_comment: 'Customers' },
|
||||
{ schema_name: 'public', table_name: 'orders', table_kind: 'r', row_count: '3', table_comment: null },
|
||||
{ schema_name: 'public', table_name: 'recent_orders', table_kind: 'v', row_count: '0', table_comment: 'Recent orders' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
@ -389,6 +389,11 @@ describe('KtxPostgresScanConnector', () => {
|
|||
});
|
||||
await expect(connector.getTableRowCount({ db: 'public', name: 'orders' })).resolves.toBe(3);
|
||||
await expect(connector.listSchemas()).resolves.toEqual(['public']);
|
||||
await expect(connector.listTables(['public'])).resolves.toEqual([
|
||||
{ schema: 'public', name: 'customers', kind: 'table' },
|
||||
{ schema: 'public', name: 'orders', kind: 'table' },
|
||||
{ schema: 'public', name: 'recent_orders', kind: 'view' },
|
||||
]);
|
||||
await expect(connector.testConnection()).resolves.toEqual({ success: true });
|
||||
|
||||
await expect(
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ function fakePoolFactory(options: { primaryKeyError?: Error; foreignKeyError?: E
|
|||
if (sql.includes('INFORMATION_SCHEMA.TABLES')) {
|
||||
return result(
|
||||
[
|
||||
{ table_name: 'customers', table_type: 'BASE TABLE' },
|
||||
{ table_name: 'orders', table_type: 'BASE TABLE' },
|
||||
{ table_name: 'order_summary', table_type: 'VIEW' },
|
||||
{ schema_name: 'dbo', table_name: 'customers', table_type: 'BASE TABLE' },
|
||||
{ schema_name: 'dbo', table_name: 'orders', table_type: 'BASE TABLE' },
|
||||
{ schema_name: 'dbo', table_name: 'order_summary', table_type: 'VIEW' },
|
||||
],
|
||||
['table_name', 'table_type'],
|
||||
);
|
||||
|
|
@ -118,6 +118,16 @@ function fakePoolFactory(options: { primaryKeyError?: Error; foreignKeyError?: E
|
|||
if (sql.includes('SUM(p.rows) AS row_count') && sql.includes('t.name = @tableName')) {
|
||||
return result([{ row_count: 2 }], ['row_count']);
|
||||
}
|
||||
if (sql.includes('FROM sys.objects o')) {
|
||||
return result(
|
||||
[
|
||||
{ schema_name: 'dbo', table_name: 'customers', table_type: 'USER_TABLE' },
|
||||
{ schema_name: 'dbo', table_name: 'order_summary', table_type: 'VIEW' },
|
||||
{ schema_name: 'dbo', table_name: 'orders', table_type: 'USER_TABLE' },
|
||||
],
|
||||
['schema_name', 'table_name', 'table_type'],
|
||||
);
|
||||
}
|
||||
if (sql.includes('SELECT s.name AS schema_name')) {
|
||||
return result([{ schema_name: 'dbo' }, { schema_name: 'sales' }], ['schema_name']);
|
||||
}
|
||||
|
|
@ -379,6 +389,11 @@ describe('KtxSqlServerScanConnector', () => {
|
|||
|
||||
await expect(connector.getTableRowCount('orders')).resolves.toBe(2);
|
||||
await expect(connector.listSchemas()).resolves.toEqual(['dbo', 'sales']);
|
||||
await expect(connector.listTables(['dbo'])).resolves.toEqual([
|
||||
{ schema: 'dbo', name: 'customers', kind: 'table' },
|
||||
{ schema: 'dbo', name: 'order_summary', kind: 'view' },
|
||||
{ schema: 'dbo', name: 'orders', kind: 'table' },
|
||||
]);
|
||||
await expect(
|
||||
connector.columnStats(
|
||||
{ connectionId: 'warehouse', table: { catalog: 'analytics', db: 'dbo', name: 'orders' }, column: 'status' },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue