Skip to content

Commit a500649

Browse files
migrate gridfs tests to unified format
1 parent 320dde0 commit a500649

17 files changed

+3535
-1207
lines changed

src/gridfs/download.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,41 @@ export interface GridFSFile {
5656

5757
/** @internal */
5858
export interface GridFSBucketReadStreamPrivate {
59+
/**
60+
* The running total number of bytes read from the chunks collection.
61+
*/
5962
bytesRead: number;
63+
/**
64+
* The number of bytes to remove from the last chunk read in the file. This is non-zero
65+
* if `end` is not equal to the length of the document and `end` is not a multiple
66+
* of the chunkSize.
67+
*/
6068
bytesToTrim: number;
69+
70+
/**
71+
* The number of bytes to remove from the first chunk read in the file. This is non-zero
72+
* if `start` is not equal to the 0 and `start` is not a multiple
73+
* of the chunkSize.
74+
*/
6175
bytesToSkip: number;
76+
77+
files: Collection<GridFSFile>;
6278
chunks: Collection<GridFSChunk>;
6379
cursor?: FindCursor<GridFSChunk>;
80+
81+
/** The running total number of chunks read from the chunks collection. */
6482
expected: number;
65-
files: Collection<GridFSFile>;
83+
84+
/**
85+
* The filter used to search in the _files_ collection (i.e., `{ _id: <> }`)
86+
* This is not the same filter used when reading chunks from the chunks collection.
87+
*/
6688
filter: Document;
89+
90+
/** Indicates whether or not download has started. */
6791
init: boolean;
92+
93+
/** The expected number of chunks to read, calculated from start, end, chunkSize and file length. */
6894
expectedEnd: number;
6995
file?: GridFSFile;
7096
options: {

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/spec/gridfs/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# GridFS Tests
2+
3+
______________________________________________________________________
4+
5+
## Introduction
6+
7+
The YAML and JSON files in this directory are platform-independent tests meant to exercise a driver's implementation of
8+
GridFS. These tests utilize the [Unified Test Format](../../unified-test-format/unified-test-format.md).
9+
10+
## Conventions for Expressing Binary Data
11+
12+
The unified test format allows binary stream data to be expressed and matched with `$$hexBytes` (for uploads) and
13+
`$$matchesHexBytes` (for downloads), respectively; however, those operators are not supported in all contexts, such as
14+
`insertData` and `outcome`. When binary data must be expressed as a base64-encoded string
15+
([Extended JSON](../../extended-json.md) for a BSON binary type), the test SHOULD include a comment noting the
16+
equivalent value in hexadecimal for human-readability. For example:
17+
18+
```yaml
19+
data: { $binary: { base64: "ESIzRA==", subType: "00" } } # hex 11223344
20+
```
21+
22+
Creating the base64-encoded string for a sequence of hexadecimal bytes is left as an exercise to the developer. Consider
23+
the following PHP one-liner:
24+
25+
```shell-session
26+
$ php -r 'echo base64_encode(hex2bin('11223344')), "\n";'
27+
ESIzRA==
28+
```

0 commit comments

Comments
 (0)