From a4ce449bb7b0e2f9edba75baf2a2f652a6750454 Mon Sep 17 00:00:00 2001 From: shisama Date: Mon, 7 May 2018 21:14:09 +0900 Subject: [PATCH] test: add tests for fs/promises chown functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To increase test coverage for fs/promises, add tests for methods chown(), filehandle.chown() and lchown(). PR-URL: https://github.com/nodejs/node/pull/20574 Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Tiancheng "Timothy" Gu --- test/parallel/test-fs-promises.js | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 26e1f8d71c292f..6bb3a871406ed2 100644 --- a/test/parallel/test-fs-promises.js +++ b/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);