Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use fs.constants for fs.access constants #49685

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: use fs.constants for fs.access constants
  • Loading branch information
LiviaMedeiros committed Sep 17, 2023
commit 7c89f23f259436eb293f92155ef33a372a94426e
32 changes: 16 additions & 16 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
@@ -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; }); };

@@ -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);

@@ -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);
}
@@ -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',
@@ -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',
@@ -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) => {
6 changes: 3 additions & 3 deletions test/parallel/test-fs-null-bytes.js
Original file line number Diff line number Diff line change
@@ -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);
@@ -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);
@@ -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);
2 changes: 1 addition & 1 deletion test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
@@ -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');