summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-truncate.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-11-26 14:06:50 -0800
committerJames M Snell <jasnell@gmail.com>2017-12-13 13:26:40 -0800
commitd453fac33b0769a12b8b926f0d77e1bbd834b397 (patch)
tree08b24c2a36e3ab2616cf83465b1ca14271d958a6 /test/parallel/test-fs-truncate.js
parent8cb080c4867bb7b8eefbb2abf34bd97c31f647a1 (diff)
downloadandroid-node-v8-d453fac33b0769a12b8b926f0d77e1bbd834b397.tar.gz
android-node-v8-d453fac33b0769a12b8b926f0d77e1bbd834b397.tar.bz2
android-node-v8-d453fac33b0769a12b8b926f0d77e1bbd834b397.zip
fs: move type checking for fs.ftruncate to js
PR-URL: https://github.com/nodejs/node/pull/17334 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-truncate.js')
-rw-r--r--test/parallel/test-fs-truncate.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/parallel/test-fs-truncate.js b/test/parallel/test-fs-truncate.js
index 4119d53c4f..7690ec7c24 100644
--- a/test/parallel/test-fs-truncate.js
+++ b/test/parallel/test-fs-truncate.js
@@ -180,8 +180,69 @@ function testFtruncate(cb) {
fs.writeFileSync(file5, 'Hi');
const fd = fs.openSync(file5, 'r+');
process.on('exit', () => fs.closeSync(fd));
+
+ ['', false, null, {}, []].forEach((i) => {
+ common.expectsError(
+ () => fs.ftruncate(fd, i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "len" argument must be of type number'
+ }
+ );
+ });
+
fs.ftruncate(fd, undefined, common.mustCall(function(err) {
assert.ifError(err);
assert(fs.readFileSync(file5).equals(Buffer.from('')));
}));
}
+
+{
+ const file6 = path.resolve(tmp, 'truncate-file-6.txt');
+ fs.writeFileSync(file6, 'Hi');
+ const fd = fs.openSync(file6, 'r+');
+ process.on('exit', () => fs.closeSync(fd));
+ fs.ftruncate(fd, -1, common.mustCall(function(err) {
+ assert.ifError(err);
+ assert(fs.readFileSync(file6).equals(Buffer.from('')));
+ }));
+}
+
+['', false, null, undefined, {}, []].forEach((i) => {
+ common.expectsError(
+ () => fs.ftruncate(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "fd" argument must be of type number'
+ }
+ );
+ common.expectsError(
+ () => fs.ftruncateSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "fd" argument must be of type number'
+ }
+ );
+});
+
+[-1, 0xFFFFFFFF + 1].forEach((i) => {
+ common.expectsError(
+ () => fs.ftruncate(i),
+ {
+ code: 'ERR_OUT_OF_RANGE',
+ type: RangeError,
+ message: 'The "fd" argument is out of range'
+ }
+ );
+ common.expectsError(
+ () => fs.ftruncateSync(i),
+ {
+ code: 'ERR_OUT_OF_RANGE',
+ type: RangeError,
+ message: 'The "fd" argument is out of range'
+ }
+ );
+});