Skip to content

Commit

Permalink
test: error when empty buffer is passed to filehandle.read()
Browse files Browse the repository at this point in the history
Added tests to occur error when empty buffer is passed to
filehandle.read() to increase coverage.

PR-URL: #23250
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
Masashi Hirano authored and danbev committed Oct 10, 2018
1 parent b6dcf8c commit a8530bc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/parallel/test-fs-read-empty-buffer.js
Expand Up @@ -6,6 +6,7 @@ const assert = require('assert');
const fs = require('fs');
const filepath = fixtures.path('x.txt');
const fd = fs.openSync(filepath, 'r');
const fsPromises = fs.promises;

const buffer = new Uint8Array();

Expand All @@ -26,3 +27,15 @@ assert.throws(
'Received Uint8Array []'
}
);

(async () => {
const filehandle = await fsPromises.open(filepath, 'r');
assert.rejects(
() => filehandle.read(buffer, 0, 1, 0),
{
code: 'ERR_INVALID_ARG_VALUE',
message: 'The argument \'buffer\' is empty and cannot be written. ' +
'Received Uint8Array []'
}
);
})();

0 comments on commit a8530bc

Please sign in to comment.