Skip to content

Commit

Permalink
test: add tests for fs/promises chown functions
Browse files Browse the repository at this point in the history
To increase test coverage for fs/promises, add tests for
methods chown(), filehandle.chown() and lchown().

PR-URL: #20574
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
  • Loading branch information
shisama authored and TimothyGu committed Jul 30, 2018
1 parent afc5636 commit a4ce449
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/parallel/test-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const fsPromises = fs.promises;
const {
access,
chmod,
chown,
copyFile,
lchown,
link,
lchmod,
lstat,
Expand Down Expand Up @@ -107,6 +109,33 @@ function verifyStatObject(stat) {
await chmod(dest, (0o10777));
await handle.chmod(0o10777);

if (!common.isWindows) {
await chown(dest, process.getuid(), process.getgid());
await handle.chown(process.getuid(), process.getgid());
}

assert.rejects(
async () => {
await chown(dest, 1, -1);
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
message: 'The value of "gid" is out of range. ' +
'It must be >= 0 && < 4294967296. Received -1'
});

assert.rejects(
async () => {
await handle.chown(1, -1);
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
message: 'The value of "gid" is out of range. ' +
'It must be >= 0 && < 4294967296. Received -1'
});

await utimes(dest, new Date(), new Date());

try {
Expand All @@ -130,6 +159,9 @@ function verifyStatObject(stat) {
if (common.canCreateSymLink()) {
const newLink = path.resolve(tmpDir, 'baz3.js');
await symlink(newPath, newLink);
if (!common.isWindows) {
await lchown(newLink, process.getuid(), process.getgid());
}
stats = await lstat(newLink);
verifyStatObject(stats);

Expand Down

0 comments on commit a4ce449

Please sign in to comment.