|
| 1 | +import { expect } from '@jest/globals'; |
| 2 | +import { BaseDriver, QuerySchemasResult } from '@cubejs-backend/base-driver'; |
| 3 | + |
| 4 | +const EXTERNAL_SCHEMA = 'spectrum_test_schema'; |
| 5 | +const EXTERNAL_TABLE = 'sales'; |
| 6 | + |
| 7 | +export function redshiftExternalSchemasSuite( |
| 8 | + execute: (name: string, test: () => Promise<void>) => void, |
| 9 | + driver: () => BaseDriver & { stream?: (query: string, values: string[], options: { highWaterMark: number }) => Promise<any> } |
| 10 | +) { |
| 11 | + execute('should establish a connection', async () => { |
| 12 | + await driver().testConnection(); |
| 13 | + }); |
| 14 | + |
| 15 | + execute('should load schemas (including external)', async () => { |
| 16 | + const inputSchemas: QuerySchemasResult[] = await driver().getSchemas(); |
| 17 | + expect(inputSchemas).toBeInstanceOf(Array); |
| 18 | + expect(inputSchemas.length).toBeGreaterThan(0); |
| 19 | + expect(inputSchemas).toContainEqual({ |
| 20 | + schema_name: EXTERNAL_SCHEMA, |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + execute('should load tables for external schema', async () => { |
| 25 | + const inputTables = await driver().getTablesForSpecificSchemas([{ schema_name: EXTERNAL_SCHEMA }]); |
| 26 | + expect(inputTables).toBeInstanceOf(Array); |
| 27 | + expect(inputTables.length).toBeGreaterThan(0); |
| 28 | + expect(inputTables).toContainEqual({ |
| 29 | + schema_name: EXTERNAL_SCHEMA, |
| 30 | + table_name: EXTERNAL_TABLE, |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + execute('should load columns for external table', async () => { |
| 35 | + const columnsForTables = await driver().getColumnsForSpecificTables([{ |
| 36 | + schema_name: EXTERNAL_SCHEMA, |
| 37 | + table_name: EXTERNAL_TABLE, |
| 38 | + }]); |
| 39 | + expect(columnsForTables).toBeInstanceOf(Array); |
| 40 | + expect(columnsForTables.length).toBeGreaterThan(0); |
| 41 | + |
| 42 | + columnsForTables.forEach((it) => { |
| 43 | + expect(it.schema_name).toEqual(EXTERNAL_SCHEMA); |
| 44 | + expect(it.table_name).toEqual(EXTERNAL_TABLE); |
| 45 | + expect(it.column_name).toEqual(expect.any(String)); |
| 46 | + expect(it.data_type).toEqual(expect.any(String)); |
| 47 | + }); |
| 48 | + }); |
| 49 | +} |
0 commit comments