Skip to content

Commit db004fc

Browse files
committed
add externalSchemaTests
1 parent 3b3fa9f commit db004fc

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

packages/cubejs-testing-drivers/src/tests/testQueries.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import {
1313
buildPreaggs,
1414
} from '../helpers';
1515
import { incrementalSchemaLoadingSuite } from './testIncrementalSchemaLoading';
16+
import { redshiftExternalSchemasSuite } from './testExternalSchemas';
1617

1718
type TestQueriesOptions = {
1819
includeIncrementalSchemaSuite?: boolean,
1920
includeHLLSuite?: boolean,
2021
extendedEnv?: string
22+
externalSchemaTests?: boolean,
2123
};
2224

23-
export function testQueries(type: string, { includeIncrementalSchemaSuite, extendedEnv, includeHLLSuite }: TestQueriesOptions = {}): void {
25+
export function testQueries(type: string, { includeIncrementalSchemaSuite, extendedEnv, includeHLLSuite, externalSchemaTests }: TestQueriesOptions = {}): void {
2426
describe(`Queries with the @cubejs-backend/${type}-driver${extendedEnv ? ` ${extendedEnv}` : ''}`, () => {
2527
jest.setTimeout(60 * 5 * 1000);
2628

@@ -1784,7 +1786,15 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten
17841786
});
17851787

17861788
if (includeIncrementalSchemaSuite) {
1787-
incrementalSchemaLoadingSuite(execute, () => driver, tables);
1789+
describe(`Incremental schema loading with @cubejs-backend/${type}-driver`, () => {
1790+
incrementalSchemaLoadingSuite(execute, () => driver, tables);
1791+
});
1792+
}
1793+
1794+
if (externalSchemaTests) {
1795+
describe(`External schema retrospection with @cubejs-backend/${type}-driver`, () => {
1796+
redshiftExternalSchemasSuite(execute, () => driver);
1797+
});
17881798
}
17891799

17901800
executePg('SQL API: powerbi min max push down', async (connection) => {

packages/cubejs-testing-drivers/test/redshift-full.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import { testQueries } from '../src/tests/testQueries';
22

33
testQueries('redshift', {
44
includeIncrementalSchemaSuite: true,
5+
externalSchemaTests: true
56
});

0 commit comments

Comments
 (0)