Skip to content

Commit 0936c5c

Browse files
committedAug 16, 2023
add duckdb test cases to test data correctness
1 parent bd598ab commit 0936c5c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
 

‎packages/extension-driver-duckdb/tests/duckdbDataSource.spec.ts

+51
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,22 @@ it('Should work with persistent database', async () => {
130130
});
131131
const columns = getColumns();
132132
const data = await streamToArray(getData());
133+
const db = new duckdb.Database(testFile);
134+
const result = await getQueryResults(
135+
db,
136+
'select * from "users" where age < 200 order by id desc'
137+
);
133138
// Assert
134139
expect(columns.length).toBe(4);
135140
expect(columns).toContainEqual({ name: 'id', type: 'number' });
136141
expect(columns).toContainEqual({ name: 'name', type: 'string' });
137142
expect(columns).toContainEqual({ name: 'age', type: 'number' });
138143
expect(columns).toContainEqual({ name: 'enabled', type: 'boolean' });
144+
expect(data.length).toEqual(result.length);
145+
for (let i = 0; i < data.length; i++) {
146+
expect(data[i]).toEqual(result[i]);
147+
}
148+
expect(data).toEqual(result);
139149
expect(data.length).toBe(2);
140150
expect(data[0]).toEqual({
141151
id: 2,
@@ -146,6 +156,47 @@ it('Should work with persistent database', async () => {
146156
expect(data[1]).toEqual({ id: 1, name: 'freda', age: 18, enabled: true });
147157
});
148158

159+
it('Should return correct data chunk', async () => {
160+
// Arrange
161+
const dataSource = new DuckDBDataSource(null, 'duckdb', [
162+
{
163+
name: 'mocked-profile',
164+
type: 'duck',
165+
connection: {
166+
'persistent-path': testFile,
167+
},
168+
allow: '*',
169+
},
170+
]);
171+
await dataSource.activate();
172+
const bindParams = new Map<string, any>();
173+
// Act
174+
const { getColumns, getData } = await dataSource.execute({
175+
statement: 'select * from "users" order by id desc',
176+
bindParams,
177+
operations: {} as any,
178+
profileName: 'mocked-profile',
179+
});
180+
const columns = getColumns();
181+
const data = await streamToArray(getData());
182+
const db = new duckdb.Database(testFile);
183+
const result = await getQueryResults(
184+
db,
185+
'select * from "users" order by id desc'
186+
);
187+
// Assert
188+
expect(columns.length).toBe(4);
189+
expect(columns).toContainEqual({ name: 'id', type: 'number' });
190+
expect(columns).toContainEqual({ name: 'name', type: 'string' });
191+
expect(columns).toContainEqual({ name: 'age', type: 'number' });
192+
expect(columns).toContainEqual({ name: 'enabled', type: 'boolean' });
193+
expect(data.length).toEqual(result.length);
194+
for (let i = 0; i < data.length; i++) {
195+
expect(data[i]).toEqual(result[i]);
196+
}
197+
expect(data.length).toBe(2000 + 3);
198+
});
199+
149200
it('Should send correct data with chunks', async () => {
150201
// Arrange
151202
const dataSource = new DuckDBDataSource(null, 'duckdb', [

0 commit comments

Comments
 (0)
Please sign in to comment.