Skip to content

Commit 2055bf5

Browse files
authored
chore: Fix tests for cloud providers (#6377)
1 parent a1f4cd4 commit 2055bf5

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

packages/cubejs-athena-driver/test/AthenaDriver.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
2-
import { DriverTests } from '@cubejs-backend/testing-shared';
2+
import { DriverTests, smartStringTrim } from '@cubejs-backend/testing-shared';
33

44
import { AthenaDriver } from '../src';
55

6+
class AthenaDriverTest extends DriverTests {
7+
protected getExpectedCsvRows() {
8+
// Athena uses \N for null values
9+
return smartStringTrim`
10+
orders__status,orders__amount
11+
new,300
12+
processed,400
13+
\N,500
14+
`;
15+
}
16+
}
17+
618
describe('AthenaDriver', () => {
7-
let tests: DriverTests;
19+
let tests: AthenaDriverTest;
820

921
jest.setTimeout(2 * 60 * 1000);
1022

1123
beforeAll(async () => {
12-
tests = new DriverTests(
24+
tests = new AthenaDriverTest(
1325
new AthenaDriver({}),
1426
{
1527
expectStringFields: true,

packages/cubejs-testing-shared/src/DriverTests.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ export class DriverTests {
4747
{ id: 4, amount: 500, status: null },
4848
];
4949

50-
public static CSV_ROWS = dedent`
51-
orders__status,orders__amount
52-
new,300
53-
processed,400
54-
`;
50+
protected getExpectedCsvRows() {
51+
return dedent`
52+
orders__status,orders__amount
53+
new,300
54+
processed,400
55+
,500
56+
`;
57+
}
5558

5659
public async testQuery() {
5760
const rows = await this.driver.query(DriverTests.QUERY, []);
@@ -73,16 +76,16 @@ export class DriverTests {
7376
SELECT orders.status AS orders__status, sum(orders.amount) AS orders__amount
7477
FROM (${DriverTests.QUERY}) AS orders
7578
GROUP BY 1
76-
ORDER BY 1
79+
ORDER BY 2
7780
`;
7881
const tableName = await this.createUnloadTable(query);
7982
assert(this.driver.unload);
8083
const data = await this.driver.unload(tableName, { maxFileSize: 64 });
8184
expect(data.csvFile.length).toEqual(1);
8285
const string = await downloadAndGunzip(data.csvFile[0]);
8386
const expectedRows = this.options.csvNoHeader
84-
? DriverTests.skipFirstLine(DriverTests.CSV_ROWS)
85-
: DriverTests.CSV_ROWS;
87+
? DriverTests.skipFirstLine(this.getExpectedCsvRows())
88+
: this.getExpectedCsvRows();
8689
expect(string.trim()).toEqual(expectedRows);
8790
}
8891

@@ -171,15 +174,17 @@ export class DriverTests {
171174
return text.split('\n').slice(1).join('\n');
172175
}
173176

174-
private static rowsToString(rows: Record<string, any>[]): Record<string, string>[] {
175-
const result: Record<string, string>[] = [];
177+
private static rowsToString(rows: Record<string, any>[]): Record<string, string | null>[] {
178+
const result: Record<string, string | null>[] = [];
179+
176180
for (const row of rows) {
177181
const newRow: Record<string, string> = {};
178182
for (const k of Object.keys(row)) {
179-
newRow[k] = row[k].toString();
183+
newRow[k] = row[k] === null ? null : row[k].toString();
180184
}
181185
result.push(newRow);
182186
}
187+
183188
return result;
184189
}
185190
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import dedent from 'dedent';
2+
13
export * from './query-test.abstract';
24
export * from './DriverTests';
35
export * from './utils';
46
export * from './response-fake';
57

68
export * from './db';
9+
10+
export const smartStringTrim = dedent;

0 commit comments

Comments
 (0)