Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(NODE-3211): convert gridfs tests to unified test format #4179

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/gridfs/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,41 @@ export interface GridFSFile {

/** @internal */
export interface GridFSBucketReadStreamPrivate {
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debugged the one skipped test for a bit before deciding to skip it - I added these comments as I was debugging and decided to leave them.

* The running total number of bytes read from the chunks collection.
*/
bytesRead: number;
/**
* The number of bytes to remove from the last chunk read in the file. This is non-zero
* if `end` is not equal to the length of the document and `end` is not a multiple
* of the chunkSize.
*/
bytesToTrim: number;

/**
* The number of bytes to remove from the first chunk read in the file. This is non-zero
* if `start` is not equal to the 0 and `start` is not a multiple
* of the chunkSize.
*/
bytesToSkip: number;

files: Collection<GridFSFile>;
chunks: Collection<GridFSChunk>;
cursor?: FindCursor<GridFSChunk>;

/** The running total number of chunks read from the chunks collection. */
expected: number;
files: Collection<GridFSFile>;

/**
* The filter used to search in the _files_ collection (i.e., `{ _id: <> }`)
* This is not the same filter used when reading chunks from the chunks collection.
*/
filter: Document;

/** Indicates whether or not download has started. */
init: boolean;

/** The expected number of chunks to read, calculated from start, end, chunkSize and file length. */
expectedEnd: number;
file?: GridFSFile;
options: {
Expand Down
235 changes: 0 additions & 235 deletions test/integration/gridfs/gridfs.spec.test.js

This file was deleted.

8 changes: 8 additions & 0 deletions test/integration/gridfs/gridfs.spec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { loadSpecTests } from '../../spec';
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

describe('GridFS Unified Tests', function () {
runUnifiedSuite(loadSpecTests('gridfs'), ({ description }) => {
return description === 'download when final chunk is missing' ? `TODO(NODE-6279): throw a missing chunk error when last chunk is missing` : false;
});
});
28 changes: 28 additions & 0 deletions test/spec/gridfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# GridFS Tests

______________________________________________________________________

## Introduction

The YAML and JSON files in this directory are platform-independent tests meant to exercise a driver's implementation of
GridFS. These tests utilize the [Unified Test Format](../../unified-test-format/unified-test-format.md).

## Conventions for Expressing Binary Data

The unified test format allows binary stream data to be expressed and matched with `$$hexBytes` (for uploads) and
`$$matchesHexBytes` (for downloads), respectively; however, those operators are not supported in all contexts, such as
`insertData` and `outcome`. When binary data must be expressed as a base64-encoded string
([Extended JSON](../../extended-json.md) for a BSON binary type), the test SHOULD include a comment noting the
equivalent value in hexadecimal for human-readability. For example:

```yaml
data: { $binary: { base64: "ESIzRA==", subType: "00" } } # hex 11223344
```

Creating the base64-encoded string for a sequence of hexadecimal bytes is left as an exercise to the developer. Consider
the following PHP one-liner:

```shell-session
$ php -r 'echo base64_encode(hex2bin('11223344')), "\n";'
ESIzRA==
```
Loading