-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-3928): don't throw error in Response constructor #3199
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,111 @@ | ||
| const { expect } = require('chai'); | ||
| const { Response } = require('../../../src/cmap/commands'); | ||
|
|
||
| describe('commands', function () { | ||
| describe('Response', function () { | ||
| describe('#parse', function () { | ||
| context('when the message body is invalid', function () { | ||
| context('when the buffer is empty', function () { | ||
| const message = Buffer.from([]); | ||
| const header = { | ||
| length: 0, | ||
| requestId: 0, | ||
| responseTo: 0, | ||
| opCode: 0 | ||
| }; | ||
| const body = Buffer.from([]); | ||
|
|
||
| it('throws an exception', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(() => response.parse()).to.throw(RangeError, /outside buffer bounds/); | ||
| }); | ||
| }); | ||
|
|
||
| context('when numReturned is invalid', function () { | ||
| const message = Buffer.from([]); | ||
| const header = { | ||
| length: 0, | ||
| requestId: 0, | ||
| responseTo: 0, | ||
| opCode: 0 | ||
| }; | ||
| const body = Buffer.alloc(5 * 4); | ||
| body.writeInt32LE(-1, 16); | ||
|
|
||
| it('throws an exception', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(() => response.parse()).to.throw(RangeError, /Invalid array length/); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#constructor', function () { | ||
| context('when the message body is invalid', function () { | ||
| const message = Buffer.from([]); | ||
| const header = { | ||
| length: 0, | ||
| requestId: 0, | ||
| responseTo: 0, | ||
| opCode: 0 | ||
| }; | ||
| const body = Buffer.from([]); | ||
|
|
||
| it('does not throw an exception', function () { | ||
| let error; | ||
| try { | ||
| new Response(message, header, body); | ||
| } catch (err) { | ||
| error = err; | ||
| } | ||
| expect(error).to.be.undefined; | ||
| }); | ||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it('initializes the documents to an empty array', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.documents).to.be.empty; | ||
| }); | ||
|
|
||
| it('does not set the responseFlags', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.responseFlags).to.be.undefined; | ||
| }); | ||
|
|
||
| it('does not set the cursorNotFound flag', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.cursorNotFound).to.be.undefined; | ||
| }); | ||
|
|
||
| it('does not set the cursorId', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.cursorId).to.be.undefined; | ||
| }); | ||
|
|
||
| it('does not set startingFrom', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.startingFrom).to.be.undefined; | ||
| }); | ||
|
|
||
| it('does not set numberReturned', function () { | ||
| const response = new Response(message, header, body); | ||
baileympearson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect(response.numberReturned).to.be.undefined; | ||
| }); | ||
|
|
||
| it('does not set queryFailure', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.queryFailure).to.be.undefined; | ||
| }); | ||
|
|
||
| it('does not set shardConfigStale', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.shardConfigStale).to.be.undefined; | ||
| }); | ||
|
|
||
| it('does not set awaitCapable', function () { | ||
| const response = new Response(message, header, body); | ||
| expect(response.awaitCapable).to.be.undefined; | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.