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 <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 targos committed Jul 31, 2018
1 parent d91742a commit 4510ca3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/parallel/test-fs-promises.js
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 4510ca3

Please sign in to comment.