-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silences warnings from mongodb client (#5025)
* Silences warnings from mongodb client * Update count, delete and finds to recommended implementations * With new parser, readPref will be null by default * Update flaky specs wih async/await style * Adds gridstore adapter spec * Use GridFSBucketStorage adapter
- Loading branch information
1 parent
d83a0b6
commit a421015
Showing
14 changed files
with
270 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const GridStoreAdapter = require('../lib/Adapters/Files/GridStoreAdapter') | ||
.GridStoreAdapter; | ||
const GridFSBucketAdapter = require('../lib/Adapters/Files/GridFSBucketAdapter') | ||
.GridFSBucketAdapter; | ||
const { randomString } = require('../lib/cryptoUtils'); | ||
const databaseURI = 'mongodb://localhost:27017/parse'; | ||
|
||
async function expectMissingFile(gfsAdapter, name) { | ||
try { | ||
await gfsAdapter.getFileData(name); | ||
fail('should have thrown'); | ||
} catch (e) { | ||
expect(e.message).toEqual('FileNotFound: file myFileName was not found'); | ||
} | ||
} | ||
|
||
describe('GridFSBucket and GridStore interop', () => { | ||
beforeEach(async () => { | ||
const gsAdapter = new GridStoreAdapter(databaseURI); | ||
const db = await gsAdapter._connect(); | ||
db.dropDatabase(); | ||
}); | ||
|
||
it('a file created in GridStore should be available in GridFS', async () => { | ||
const gsAdapter = new GridStoreAdapter(databaseURI); | ||
const gfsAdapter = new GridFSBucketAdapter(databaseURI); | ||
await expectMissingFile(gfsAdapter, 'myFileName'); | ||
const originalString = 'abcdefghi'; | ||
await gsAdapter.createFile('myFileName', originalString); | ||
const gsResult = await gsAdapter.getFileData('myFileName'); | ||
expect(gsResult.toString('utf8')).toBe(originalString); | ||
const gfsResult = await gfsAdapter.getFileData('myFileName'); | ||
expect(gfsResult.toString('utf8')).toBe(originalString); | ||
}); | ||
|
||
it('properly fetches a large file from GridFS', async () => { | ||
const gfsAdapter = new GridFSBucketAdapter(databaseURI); | ||
const twoMegabytesFile = randomString(2048 * 1024); | ||
await gfsAdapter.createFile('myFileName', twoMegabytesFile); | ||
const gfsResult = await gfsAdapter.getFileData('myFileName'); | ||
expect(gfsResult.toString('utf8')).toBe(twoMegabytesFile); | ||
}); | ||
|
||
it( | ||
'properly deletes a file from GridFS', | ||
async () => { | ||
const gfsAdapter = new GridFSBucketAdapter(databaseURI); | ||
await gfsAdapter.createFile('myFileName', 'a simple file'); | ||
await gfsAdapter.deleteFile('myFileName'); | ||
await expectMissingFile(gfsAdapter, 'myFileName'); | ||
}, | ||
1000000 | ||
); | ||
|
||
it('properly overrides files', async () => { | ||
const gfsAdapter = new GridFSBucketAdapter(databaseURI); | ||
await gfsAdapter.createFile('myFileName', 'a simple file'); | ||
await gfsAdapter.createFile('myFileName', 'an overrided simple file'); | ||
const data = await gfsAdapter.getFileData('myFileName'); | ||
expect(data.toString('utf8')).toBe('an overrided simple file'); | ||
const bucket = await gfsAdapter._getBucket(); | ||
const documents = await bucket.find({ filename: 'myFileName' }).toArray(); | ||
expect(documents.length).toBe(2); | ||
await gfsAdapter.deleteFile('myFileName'); | ||
await expectMissingFile(gfsAdapter, 'myFileName'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.