aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-open.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-10 23:06:33 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-15 17:38:12 +0100
commit1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e (patch)
tree0c43b3ce5635fd76d6c9aabc1a37fe638cbdb0be /test/parallel/test-fs-open.js
parent6f77af541e4336037f08a876e1a3fa657fd22675 (diff)
downloadandroid-node-v8-1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e.tar.gz
android-node-v8-1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e.tar.bz2
android-node-v8-1cdeb9f956a9f54dde7c6b1a792b97584acbfb8e.zip
fs: improve mode validation
Do not return a default mode in case invalid mode values are provided. This strictens and simplifies the function by reusing existing functionality. PR-URL: https://github.com/nodejs/node/pull/26575 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Diffstat (limited to 'test/parallel/test-fs-open.js')
-rw-r--r--test/parallel/test-fs-open.js43
1 files changed, 32 insertions, 11 deletions
diff --git a/test/parallel/test-fs-open.js b/test/parallel/test-fs-open.js
index 9a1ae623fe..79b78ff2ef 100644
--- a/test/parallel/test-fs-open.js
+++ b/test/parallel/test-fs-open.js
@@ -98,15 +98,36 @@ for (const extra of [[], ['r'], ['r', 0], ['r', 0, 'bad callback']]) {
type: TypeError
}
);
- fs.promises.open(i, 'r')
- .then(common.mustNotCall())
- .catch(common.mustCall((err) => {
- common.expectsError(
- () => { throw err; },
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError
- }
- );
- }));
+ assert.rejects(
+ fs.promises.open(i, 'r'),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]'
+ }
+ );
+});
+
+// Check invalid modes.
+[false, [], {}].forEach((mode) => {
+ assert.throws(
+ () => fs.open(__filename, 'r', mode, common.mustNotCall()),
+ {
+ message: /'mode' must be a 32-bit/,
+ code: 'ERR_INVALID_ARG_VALUE'
+ }
+ );
+ assert.throws(
+ () => fs.openSync(__filename, 'r', mode, common.mustNotCall()),
+ {
+ message: /'mode' must be a 32-bit/,
+ code: 'ERR_INVALID_ARG_VALUE'
+ }
+ );
+ assert.rejects(
+ fs.promises.open(__filename, 'r', mode),
+ {
+ message: /'mode' must be a 32-bit/,
+ code: 'ERR_INVALID_ARG_VALUE'
+ }
+ );
});