Skip to content
Permalink
Browse files

test: add tests for fs/promises chown functions

To increase test coverage for fs/promises, add tests for
methods chown(), filehandle.chown() and lchown().

PR-URL: #20574
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
  • Loading branch information...
shisama authored and TimothyGu committed May 7, 2018
1 parent afc5636 commit a4ce449bb7b0e2f9edba75baf2a2f652a6750454
Showing with 32 additions and 0 deletions.
  1. +32 −0 test/parallel/test-fs-promises.js
@@ -10,7 +10,9 @@ const fsPromises = fs.promises;
const {
access,
chmod,
chown,
copyFile,
lchown,
link,
lchmod,
lstat,
@@ -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 {
@@ -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);

0 comments on commit a4ce449

Please sign in to comment.
You can’t perform that action at this time.