Skip to content

Commit

Permalink
test: improve fs coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed May 3, 2021
1 parent 68e6673 commit 04dc1f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/parallel/test-fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ assert.throws(
}
);

['buffer', 'offset', 'length'].forEach((option) =>
['buffer', 'offset', 'length'].forEach((option) => {
assert.throws(
() => fs.read(fd, {
[option]: null
}),
`not throws when options.${option} is null`
));
);
assert.throws(
() => fs.readSync(fd, {
[option]: null
}),
`not throws when options.${option} is null`
);
});

assert.throws(
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-fs-readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ for (const e of fileInfo) {
assert.deepStrictEqual(buf, e.contents);
}));
}
// Test readFile size too large
{
const kIoMaxLength = 2 ** 31 - 1;

const file = path.join(tmpdir.path, `${prefix}-too-large.txt`);
fs.writeFileSync(file, Buffer.from('0'));
fs.truncateSync(file, kIoMaxLength + 1);

fs.readFile(file, common.mustCall((err) => {
assert.strictEqual(err.name, 'RangeError');
assert.strictEqual(err.code, 'ERR_FS_FILE_TOO_LARGE');
}));
assert.throws(() => {
fs.readFileSync(file);
}, { code: 'ERR_FS_FILE_TOO_LARGE', name: 'RangeError' });
}

{
// Test cancellation, before
const signal = AbortSignal.abort();
Expand Down

0 comments on commit 04dc1f1

Please sign in to comment.