Skip to content

Commit 4510ca3

Browse files
shisamatargos
shisama
authored andcommitted
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 <[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]>
1 parent d91742a commit 4510ca3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/parallel/test-fs-promises.js

+32
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const fsPromises = fs.promises;
1010
const {
1111
access,
1212
chmod,
13+
chown,
1314
copyFile,
15+
lchown,
1416
link,
1517
lchmod,
1618
lstat,
@@ -107,6 +109,33 @@ function verifyStatObject(stat) {
107109
await chmod(dest, (0o10777));
108110
await handle.chmod(0o10777);
109111

112+
if (!common.isWindows) {
113+
await chown(dest, process.getuid(), process.getgid());
114+
await handle.chown(process.getuid(), process.getgid());
115+
}
116+
117+
assert.rejects(
118+
async () => {
119+
await chown(dest, 1, -1);
120+
},
121+
{
122+
code: 'ERR_OUT_OF_RANGE',
123+
name: 'RangeError [ERR_OUT_OF_RANGE]',
124+
message: 'The value of "gid" is out of range. ' +
125+
'It must be >= 0 && < 4294967296. Received -1'
126+
});
127+
128+
assert.rejects(
129+
async () => {
130+
await handle.chown(1, -1);
131+
},
132+
{
133+
code: 'ERR_OUT_OF_RANGE',
134+
name: 'RangeError [ERR_OUT_OF_RANGE]',
135+
message: 'The value of "gid" is out of range. ' +
136+
'It must be >= 0 && < 4294967296. Received -1'
137+
});
138+
110139
await utimes(dest, new Date(), new Date());
111140

112141
try {
@@ -130,6 +159,9 @@ function verifyStatObject(stat) {
130159
if (common.canCreateSymLink()) {
131160
const newLink = path.resolve(tmpDir, 'baz3.js');
132161
await symlink(newPath, newLink);
162+
if (!common.isWindows) {
163+
await lchown(newLink, process.getuid(), process.getgid());
164+
}
133165
stats = await lstat(newLink);
134166
verifyStatObject(stats);
135167

0 commit comments

Comments
 (0)