Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRongjian Zhang <pd4d10@gmail.com>2021-05-20 16:01:53 +0300
committerXadillaX <i@2333.moe>2021-06-02 08:45:29 +0300
commitdef57580fce7a0ca6acd215371028efc7fdb3f5f (patch)
tree20c8cf3276dc7a56d34bc8c06a76ba564786aadb /test
parent2bb0c2013f3592f7a7a3c514eb9f47482b751d9a (diff)
test: improve coverage of fs internal utils
Refs: https://coverage.nodejs.org/coverage-910efc2d9a69ac32/lib/internal/fs/utils.js.html#L634 PR-URL: https://github.com/nodejs/node/pull/38746 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-fs-util-validateoffsetlength.js87
-rw-r--r--test/parallel/test-fs-util-validateoffsetlengthwrite.js43
2 files changed, 87 insertions, 43 deletions
diff --git a/test/parallel/test-fs-util-validateoffsetlength.js b/test/parallel/test-fs-util-validateoffsetlength.js
new file mode 100644
index 00000000000..28e087d33ae
--- /dev/null
+++ b/test/parallel/test-fs-util-validateoffsetlength.js
@@ -0,0 +1,87 @@
+// Flags: --expose-internals
+'use strict';
+
+const common = require('../common');
+
+const assert = require('assert');
+const {
+ validateOffsetLengthRead,
+ validateOffsetLengthWrite,
+} = require('internal/fs/utils');
+
+{
+ const offset = -1;
+ assert.throws(
+ () => validateOffsetLengthRead(offset, 0, 0),
+ common.expectsError({
+ code: 'ERR_OUT_OF_RANGE',
+ name: 'RangeError',
+ message: 'The value of "offset" is out of range. ' +
+ `It must be >= 0. Received ${offset}`
+ })
+ );
+}
+
+{
+ const length = -1;
+ assert.throws(
+ () => validateOffsetLengthRead(0, length, 0),
+ common.expectsError({
+ code: 'ERR_OUT_OF_RANGE',
+ name: 'RangeError',
+ message: 'The value of "length" is out of range. ' +
+ `It must be >= 0. Received ${length}`
+ })
+ );
+}
+
+{
+ const offset = 1;
+ const length = 1;
+ const byteLength = offset + length - 1;
+ assert.throws(
+ () => validateOffsetLengthRead(offset, length, byteLength),
+ common.expectsError({
+ code: 'ERR_OUT_OF_RANGE',
+ name: 'RangeError',
+ message: 'The value of "length" is out of range. ' +
+ `It must be <= ${byteLength - offset}. Received ${length}`
+ })
+ );
+}
+
+// Most platforms don't allow reads or writes >= 2 GB.
+// See https://github.com/libuv/libuv/pull/1501.
+const kIoMaxLength = 2 ** 31 - 1;
+
+// RangeError when offset > byteLength
+{
+ const offset = 100;
+ const length = 100;
+ const byteLength = 50;
+ assert.throws(
+ () => validateOffsetLengthWrite(offset, length, byteLength),
+ common.expectsError({
+ code: 'ERR_OUT_OF_RANGE',
+ name: 'RangeError',
+ message: 'The value of "offset" is out of range. ' +
+ `It must be <= ${byteLength}. Received ${offset}`
+ })
+ );
+}
+
+// RangeError when byteLength < kIoMaxLength, and length > byteLength - offset.
+{
+ const offset = kIoMaxLength - 150;
+ const length = 200;
+ const byteLength = kIoMaxLength - 100;
+ assert.throws(
+ () => validateOffsetLengthWrite(offset, length, byteLength),
+ common.expectsError({
+ code: 'ERR_OUT_OF_RANGE',
+ name: 'RangeError',
+ message: 'The value of "length" is out of range. ' +
+ `It must be <= ${byteLength - offset}. Received ${length}`
+ })
+ );
+}
diff --git a/test/parallel/test-fs-util-validateoffsetlengthwrite.js b/test/parallel/test-fs-util-validateoffsetlengthwrite.js
deleted file mode 100644
index 57fb7a9bc70..00000000000
--- a/test/parallel/test-fs-util-validateoffsetlengthwrite.js
+++ /dev/null
@@ -1,43 +0,0 @@
-// Flags: --expose-internals
-'use strict';
-
-require('../common');
-
-const assert = require('assert');
-const { validateOffsetLengthWrite } = require('internal/fs/utils');
-
-// Most platforms don't allow reads or writes >= 2 GB.
-// See https://github.com/libuv/libuv/pull/1501.
-const kIoMaxLength = 2 ** 31 - 1;
-
-// RangeError when offset > byteLength
-{
- const offset = 100;
- const length = 100;
- const byteLength = 50;
- assert.throws(
- () => validateOffsetLengthWrite(offset, length, byteLength),
- {
- code: 'ERR_OUT_OF_RANGE',
- name: 'RangeError',
- message: 'The value of "offset" is out of range. ' +
- `It must be <= ${byteLength}. Received ${offset}`
- }
- );
-}
-
-// RangeError when byteLength < kIoMaxLength, and length > byteLength - offset.
-{
- const offset = kIoMaxLength - 150;
- const length = 200;
- const byteLength = kIoMaxLength - 100;
- assert.throws(
- () => validateOffsetLengthWrite(offset, length, byteLength),
- {
- code: 'ERR_OUT_OF_RANGE',
- name: 'RangeError',
- message: 'The value of "length" is out of range. ' +
- `It must be <= ${byteLength - offset}. Received ${length}`
- }
- );
-}