Skip to content

Commit 7434838

Browse files
implement tests
1 parent 03aefac commit 7434838

File tree

3 files changed

+27
-252
lines changed

3 files changed

+27
-252
lines changed

test/integration/gridfs/gridfs.spec.test.js

Lines changed: 0 additions & 235 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { loadSpecTests } from '../../spec';
2+
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
3+
4+
describe('GridFS Unified Tests', function () {
5+
runUnifiedSuite(loadSpecTests('gridfs'), ({ description }) => {
6+
return description === 'download when final chunk is missing' ? `TODO(NODE-xxxx)` : false;
7+
});
8+
});

test/tools/unified-spec-runner/operations.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
3-
import { once, Writable } from 'node:stream';
2+
3+
import { once, Readable, Writable } from 'node:stream';
4+
import { pipeline } from 'node:stream/promises';
45

56
import { AssertionError, expect } from 'chai';
67

@@ -519,27 +520,28 @@ operations.set('delete', async ({ entities, operation }) => {
519520
operations.set('download', async ({ entities, operation }) => {
520521
const bucket = entities.getEntity('bucket', operation.object);
521522

522-
const stream = bucket.openDownloadStream(operation.arguments!.id);
523-
return new Promise((resolve, reject) => {
524-
const chunks: any[] = [];
525-
stream.on('data', chunk => chunks.push(...chunk));
526-
stream.on('error', reject);
527-
stream.on('end', () => resolve(chunks));
528-
});
523+
const { id, ...options } = operation.arguments ?? {};
524+
const stream = bucket.openDownloadStream(id, options);
525+
return Buffer.concat(await stream.toArray());
529526
});
530527

531-
operations.set('upload', async ({ entities, operation }) => {
528+
operations.set('downloadByName', async ({ entities, operation }) => {
532529
const bucket = entities.getEntity('bucket', operation.object);
533530

534-
const stream = bucket.openUploadStream(operation.arguments!.filename, {
535-
chunkSizeBytes: operation.arguments?.chunkSizeBytes
536-
});
531+
const { filename, ...options } = operation.arguments ?? {};
532+
const stream: Readable = bucket.openDownloadStreamByName(filename, options);
533+
534+
return Buffer.concat(await stream.toArray());
535+
});
536+
537+
operations.set('upload', async ({ entities, operation }) => {
538+
const bucket = entities.getEntity('bucket', operation.object);
539+
const { filename, source, ...options } = operation.arguments ?? {};
537540

538-
const data = Buffer.from(operation.arguments!.source.$$hexBytes, 'hex');
539-
const willFinish = once(stream, 'finish');
540-
stream.end(data);
541-
await willFinish;
541+
const stream = bucket.openUploadStream(operation.arguments!.filename, options);
542+
const filestream = Readable.from(Buffer.from(operation.arguments!.source.$$hexBytes, 'hex'));
542543

544+
await pipeline(filestream, stream);
543545
return stream.gridFSFile?._id;
544546
});
545547

0 commit comments

Comments
 (0)