Skip to content

Commit

Permalink
test: change expected error code from EPERM to EACCES
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Mar 16, 2022
1 parent 4dea5e7 commit 061e0db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
8 changes: 4 additions & 4 deletions test/parallel/test-fs-error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ fs.writeFileSync(existingFile2, 'test', 'utf-8');
const { COPYFILE_EXCL } = fs.constants;
const { internalBinding } = require('internal/test/binding');
const {
UV_EACCES,
UV_EBADF,
UV_EEXIST,
UV_EINVAL,
UV_ENOENT,
UV_ENOTDIR,
UV_ENOTEMPTY,
UV_EPERM
} = internalBinding('uv');

// Template tag function for escaping special characters in strings so that:
Expand Down Expand Up @@ -333,10 +333,10 @@ function re(literals, ...values) {
} else { // windows
assert.strictEqual(
err.message,
`EPERM: operation not permitted, rename '${existingDir}' -> ` +
`EACCES: permission denied, rename '${existingDir}' -> ` +
`'${existingDir2}'`);
assert.strictEqual(err.errno, UV_EPERM);
assert.strictEqual(err.code, 'EPERM');
assert.strictEqual(err.errno, UV_EACCES);
assert.strictEqual(err.code, 'EACCES');
}
return true;
};
Expand Down
15 changes: 6 additions & 9 deletions test/parallel/test-fs-mkdir-recursive-eaccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ const path = require('path');
let n = 0;

function makeDirectoryReadOnly(dir) {
let accessErrorCode = 'EACCES';
if (common.isWindows) {
accessErrorCode = 'EPERM';
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC,AD,WD)"`);
} else {
fs.chmodSync(dir, '444');
}
return accessErrorCode;
}

function makeDirectoryWritable(dir) {
Expand All @@ -39,11 +36,11 @@ function makeDirectoryWritable(dir) {
}
}

// Synchronous API should return an EACCESS error with path populated.
// Synchronous API should return an EACCES error with path populated.
{
const dir = path.join(tmpdir.path, `mkdirp_${n++}`);
fs.mkdirSync(dir);
const codeExpected = makeDirectoryReadOnly(dir);
makeDirectoryReadOnly(dir);
let err = null;
try {
fs.mkdirSync(path.join(dir, '/foo'), { recursive: true });
Expand All @@ -52,19 +49,19 @@ function makeDirectoryWritable(dir) {
}
makeDirectoryWritable(dir);
assert(err);
assert.strictEqual(err.code, codeExpected);
assert.strictEqual(err.code, 'EACCES');
assert(err.path);
}

// Asynchronous API should return an EACCESS error with path populated.
// Asynchronous API should return an EACCES error with path populated.
{
const dir = path.join(tmpdir.path, `mkdirp_${n++}`);
fs.mkdirSync(dir);
const codeExpected = makeDirectoryReadOnly(dir);
makeDirectoryReadOnly(dir);
fs.mkdir(path.join(dir, '/bar'), { recursive: true }, (err) => {
makeDirectoryWritable(dir);
assert(err);
assert.strictEqual(err.code, codeExpected);
assert.strictEqual(err.code, 'EACCES');
assert(err.path);
});
}
11 changes: 4 additions & 7 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,11 @@ function removeAsync(dir) {
// This test should not be run as `root`
if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) {
function makeDirectoryReadOnly(dir, mode) {
let accessErrorCode = 'EACCES';
if (common.isWindows) {
accessErrorCode = 'EPERM';
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC)"`);
} else {
fs.chmodSync(dir, mode);
}
return accessErrorCode;
}

function makeDirectoryWritable(dir) {
Expand All @@ -342,11 +339,11 @@ function removeAsync(dir) {
try {
fs.mkdirSync(dirname, { recursive: true });
fs.writeFileSync(filePath, 'hello');
const code = makeDirectoryReadOnly(dirname, 0o444);
makeDirectoryReadOnly(dirname, 0o444);
assert.throws(() => {
fs.rmSync(filePath, { force: true });
}, {
code,
code: 'EACCES',
name: 'Error',
});
} finally {
Expand All @@ -364,12 +361,12 @@ function removeAsync(dir) {
fs.mkdirSync(middle);
fs.mkdirSync(path.join(middle, 'leaf')); // Make `middle` non-empty
try {
const code = makeDirectoryReadOnly(middle, 0o555);
makeDirectoryReadOnly(middle, 0o555);
try {
assert.throws(() => {
fs.rmSync(root, { recursive: true });
}, {
code,
code: 'EACCES',
name: 'Error',
});
} catch (err) {
Expand Down

0 comments on commit 061e0db

Please sign in to comment.