Skip to content

Commit

Permalink
test: use fs.constants for fs.access constants
Browse files Browse the repository at this point in the history
PR-URL: nodejs#49685
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
LiviaMedeiros authored Sep 20, 2023
1 parent 346abdd commit cdad3d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
32 changes: 16 additions & 16 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ if (!common.isWindows && process.getuid() === 0) {
}
}

assert.strictEqual(typeof fs.F_OK, 'number');
assert.strictEqual(typeof fs.R_OK, 'number');
assert.strictEqual(typeof fs.W_OK, 'number');
assert.strictEqual(typeof fs.X_OK, 'number');
assert.strictEqual(typeof fs.constants.F_OK, 'number');
assert.strictEqual(typeof fs.constants.R_OK, 'number');
assert.strictEqual(typeof fs.constants.W_OK, 'number');
assert.strictEqual(typeof fs.constants.X_OK, 'number');

const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };

Expand All @@ -76,16 +76,16 @@ fs.access(__filename, common.mustCall(function(...args) {
fs.promises.access(__filename)
.then(common.mustCall())
.catch(throwNextTick);
fs.access(__filename, fs.R_OK, common.mustCall(function(...args) {
fs.access(__filename, fs.constants.R_OK, common.mustCall(function(...args) {
assert.deepStrictEqual(args, [null]);
}));
fs.promises.access(__filename, fs.R_OK)
fs.promises.access(__filename, fs.constants.R_OK)
.then(common.mustCall())
.catch(throwNextTick);
fs.access(readOnlyFile, fs.R_OK, common.mustCall(function(...args) {
fs.access(readOnlyFile, fs.constants.R_OK, common.mustCall(function(...args) {
assert.deepStrictEqual(args, [null]);
}));
fs.promises.access(readOnlyFile, fs.R_OK)
fs.promises.access(readOnlyFile, fs.constants.R_OK)
.then(common.mustCall())
.catch(throwNextTick);

Expand All @@ -111,8 +111,8 @@ fs.promises.access(readOnlyFile, fs.R_OK)
assert.strictEqual(err.path, readOnlyFile);
}
}
fs.access(readOnlyFile, fs.W_OK, common.mustCall(expectedError));
fs.promises.access(readOnlyFile, fs.W_OK)
fs.access(readOnlyFile, fs.constants.W_OK, common.mustCall(expectedError));
fs.promises.access(readOnlyFile, fs.constants.W_OK)
.then(common.mustNotCall(), common.mustCall(expectedError))
.catch(throwNextTick);
}
Expand All @@ -124,18 +124,18 @@ fs.promises.access(readOnlyFile, fs.R_OK)
return true;
};
assert.throws(
() => { fs.access(100, fs.F_OK, common.mustNotCall()); },
() => { fs.access(100, fs.constants.F_OK, common.mustNotCall()); },
expectedError
);

fs.promises.access(100, fs.F_OK)
fs.promises.access(100, fs.constants.F_OK)
.then(common.mustNotCall(), common.mustCall(expectedError))
.catch(throwNextTick);
}

assert.throws(
() => {
fs.access(__filename, fs.F_OK);
fs.access(__filename, fs.constants.F_OK);
},
{
code: 'ERR_INVALID_ARG_TYPE',
Expand All @@ -144,7 +144,7 @@ assert.throws(

assert.throws(
() => {
fs.access(__filename, fs.F_OK, common.mustNotMutateObjectDeep({}));
fs.access(__filename, fs.constants.F_OK, common.mustNotMutateObjectDeep({}));
},
{
code: 'ERR_INVALID_ARG_TYPE',
Expand All @@ -153,14 +153,14 @@ assert.throws(

// Regular access should not throw.
fs.accessSync(__filename);
const mode = fs.R_OK | fs.W_OK;
const mode = fs.constants.R_OK | fs.constants.W_OK;
fs.accessSync(readWriteFile, mode);

// Invalid modes should throw.
[
false,
1n,
{ [Symbol.toPrimitive]() { return fs.R_OK; } },
{ [Symbol.toPrimitive]() { return fs.constants.R_OK; } },
[1],
'r',
].forEach((mode, i) => {
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-fs-null-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function check(async, sync) {
}

check(fs.access, fs.accessSync, 'foo\u0000bar');
check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK);
check(fs.access, fs.accessSync, 'foo\u0000bar', fs.constants.F_OK);
check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar', 'abc');
check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644');
check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34);
Expand Down Expand Up @@ -87,7 +87,7 @@ const fileUrl = new URL('file:///C:/foo\u0000bar');
const fileUrl2 = new URL('file:///C:/foo%00bar');

check(fs.access, fs.accessSync, fileUrl);
check(fs.access, fs.accessSync, fileUrl, fs.F_OK);
check(fs.access, fs.accessSync, fileUrl, fs.constants.F_OK);
check(fs.appendFile, fs.appendFileSync, fileUrl, 'abc');
check(fs.chmod, fs.chmodSync, fileUrl, '0644');
check(fs.chown, fs.chownSync, fileUrl, 12, 34);
Expand Down Expand Up @@ -119,7 +119,7 @@ check(null, fs.watchFile, fileUrl, assert.fail);
check(fs.writeFile, fs.writeFileSync, fileUrl, 'abc');

check(fs.access, fs.accessSync, fileUrl2);
check(fs.access, fs.accessSync, fileUrl2, fs.F_OK);
check(fs.access, fs.accessSync, fileUrl2, fs.constants.F_OK);
check(fs.appendFile, fs.appendFileSync, fileUrl2, 'abc');
check(fs.chmod, fs.chmodSync, fileUrl2, '0644');
check(fs.chown, fs.chownSync, fileUrl2, 12, 34);
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
req.oncomplete = () => { };

testInitialized(req, 'FSReqCallback');
binding.access(path.toNamespacedPath('../'), fs.F_OK, req);
binding.access(path.toNamespacedPath('../'), fs.constants.F_OK, req);

const StatWatcher = binding.StatWatcher;
testInitialized(new StatWatcher(), 'StatWatcher');
Expand Down

0 comments on commit cdad3d8

Please sign in to comment.