Skip to content

Commit

Permalink
test: removing common.expectsError since it's not needed anymore for …
Browse files Browse the repository at this point in the history
…asserts
  • Loading branch information
AndresMorelos committed Jan 3, 2024
1 parent 084d761 commit e92b6c0
Showing 1 changed file with 49 additions and 49 deletions.
98 changes: 49 additions & 49 deletions test/fixtures/permission/fs-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder);
{
assert.throws(() => {
fs.writeFile(blockedFile, 'example', () => {});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFile),
}));
});
assert.throws(() => {
fs.writeFile(relativeProtectedFile, 'example', () => {});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(absoluteProtectedFile),
}));
});

assert.throws(() => {
fs.writeFile(path.join(blockedFolder, 'anyfile'), 'example', () => {});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')),
}));
});
}

// fs.createWriteStream
Expand All @@ -54,69 +54,69 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder);
const stream = fs.createWriteStream(blockedFile);
stream.on('error', reject);
});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFile),
})).then(common.mustCall());
}).then(common.mustCall());
assert.rejects(() => {
return new Promise((_resolve, reject) => {
const stream = fs.createWriteStream(relativeProtectedFile);
stream.on('error', reject);
});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(absoluteProtectedFile),
})).then(common.mustCall());
}).then(common.mustCall());

assert.rejects(() => {
return new Promise((_resolve, reject) => {
const stream = fs.createWriteStream(path.join(blockedFolder, 'example'));
stream.on('error', reject);
});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(blockedFolder, 'example')),
})).then(common.mustCall());
}).then(common.mustCall());
}

// fs.utimes
{
assert.throws(() => {
fs.utimes(blockedFile, new Date(), new Date(), () => {});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFile),
}));
});
assert.throws(() => {
fs.utimes(relativeProtectedFile, new Date(), new Date(), () => {});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(absoluteProtectedFile),
}));
});

assert.throws(() => {
fs.utimes(path.join(blockedFolder, 'anyfile'), new Date(), new Date(), () => {});
}, common.expectsError({
}, {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')),
}));
});
}

// fs.lutimes
{
assert.throws(() => {
fs.lutimes(blockedFile, new Date(), new Date(), () => {});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFile),
}));
});
}

// fs.mkdir
Expand All @@ -125,37 +125,37 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder);
fs.mkdir(path.join(blockedFolder, 'any-folder'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(blockedFolder, 'any-folder')),
}));
});
assert.throws(() => {
fs.mkdir(path.join(relativeProtectedFolder, 'any-folder'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(absoluteProtectedFolder, 'any-folder')),
}));
});
}

{
assert.throws(() => {
fs.mkdtempSync(path.join(blockedFolder, 'any-folder'));
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
}));
});
assert.throws(() => {
fs.mkdtemp(path.join(relativeProtectedFolder, 'any-folder'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
}));
});
}

// fs.rename
Expand All @@ -164,93 +164,93 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder);
fs.rename(blockedFile, path.join(blockedFile, 'renamed'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFile),
}));
});
assert.throws(() => {
fs.rename(relativeProtectedFile, path.join(relativeProtectedFile, 'renamed'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(absoluteProtectedFile),
}));
});
assert.throws(() => {
fs.rename(blockedFile, path.join(regularFolder, 'renamed'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFile),
}));
});

assert.throws(() => {
fs.rename(regularFile, path.join(blockedFolder, 'renamed'), (err) => {
assert.ifError(err);
});
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(blockedFolder, 'renamed')),
}));
});
}

// fs.copyFile
{
assert.throws(() => {
fs.copyFileSync(regularFile, path.join(blockedFolder, 'any-file'));
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(blockedFolder, 'any-file')),
}));
});
assert.throws(() => {
fs.copyFileSync(regularFile, path.join(relativeProtectedFolder, 'any-file'));
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(absoluteProtectedFolder, 'any-file')),
}));
});
}

// fs.cp
{
assert.throws(() => {
fs.cpSync(regularFile, path.join(blockedFolder, 'any-file'));
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(blockedFolder, 'any-file')),
}));
});
assert.throws(() => {
fs.cpSync(regularFile, path.join(relativeProtectedFolder, 'any-file'));
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(path.join(absoluteProtectedFolder, 'any-file')),
}));
});
}

// fs.rm
{
assert.throws(() => {
fs.rmSync(blockedFolder, { recursive: true });
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFolder),
}));
});
assert.throws(() => {
fs.rmSync(relativeProtectedFolder, { recursive: true });
}, common.expectsError({
},{
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(absoluteProtectedFolder),
}));
});
}

// fs.open
Expand Down Expand Up @@ -391,4 +391,4 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder);
permission: 'FileSystemWrite',
resource: path.toNamespacedPath(blockedFile),
});
}
}

0 comments on commit e92b6c0

Please sign in to comment.