From fffdce1c68ba958a335ac6ac4bc5a01a4ecc4267 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Wed, 4 Apr 2018 16:29:18 -0400 Subject: [PATCH 1/3] Increase test coverage for fs/promises.js --- test/parallel/test-fs-promises.js | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index ba3a91d5b39f8a..adb88711baaad7 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -82,24 +82,44 @@ function verifyStatObject(stat) { stats = await stat(dest); verifyStatObject(stats); + stats = await handle.stat(); + verifyStatObject(stats); + await fdatasync(handle); + await handle.datasync(); await fsync(handle); + await handle.sync(); const buf = Buffer.from('hello world'); - await write(handle, buf); - const ret = await read(handle, Buffer.alloc(11), 0, 11, 0); assert.strictEqual(ret.bytesRead, 11); assert.deepStrictEqual(ret.buffer, buf); + const buf2 = Buffer.from('HELLO WORLD'); + await handle.write(buf2); + const ret2 = await handle.read(Buffer.alloc(11), 0, 11, 0); + assert.strictEqual(ret2.bytesRead, 11); + assert.deepStrictEqual(ret2.buffer, buf); + await chmod(dest, 0o666); await fchmod(handle, 0o666); + handle.chmod(0o666); + try { + await fchmod(handle, (0o777 + 1)); + } catch (err) { + // mode can't be > 0o777 + common.expectsError({ + code: 'ERR_OUT_OF_RANGE', + type: RangeError + })(err); + } await utimes(dest, new Date(), new Date()); try { await futimes(handle, new Date(), new Date()); + await handle.utimes(new Date(), new Date()); } catch (err) { // Some systems do not have futimes. If there is an error, // expect it to be ENOSYS @@ -147,6 +167,16 @@ function verifyStatObject(stat) { await rmdir(newdir); await mkdtemp(path.resolve(tmpDir, 'FOO')); + try { + await mkdtemp(1); + } catch (err) { + // mkdtemp() expects to get a string prefix. + console.log('err', err); + common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError + })(err); + } } doTest().then(common.mustCall()); From d20bde9847a83b18bf07cd42da41fe9b527fa6a9 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Mon, 30 Apr 2018 15:41:42 -0400 Subject: [PATCH 2/3] Address review comments --- test/parallel/test-fs-promises.js | 63 +++++++++++++++++++------------ 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index adb88711baaad7..887552bde2653c 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -90,30 +90,46 @@ function verifyStatObject(stat) { await fsync(handle); await handle.sync(); - const buf = Buffer.from('hello world'); + const buf = Buffer.from('hello fsPromises'); + const bufLen = buf.length; await write(handle, buf); - const ret = await read(handle, Buffer.alloc(11), 0, 11, 0); - assert.strictEqual(ret.bytesRead, 11); + const ret = await read(handle, Buffer.alloc(bufLen), 0, bufLen, 0); + assert.strictEqual(ret.bytesRead, bufLen); assert.deepStrictEqual(ret.buffer, buf); - const buf2 = Buffer.from('HELLO WORLD'); - await handle.write(buf2); - const ret2 = await handle.read(Buffer.alloc(11), 0, 11, 0); - assert.strictEqual(ret2.bytesRead, 11); - assert.deepStrictEqual(ret2.buffer, buf); + const buf2 = Buffer.from('hello FileHandle'); + const buf2Len = buf2.length; + await handle.write(buf2, 0, buf2Len, 0); + const ret2 = await handle.read(Buffer.alloc(buf2Len), 0, buf2Len, 0); + assert.strictEqual(ret2.bytesRead, buf2Len); + assert.deepStrictEqual(ret2.buffer, buf2); await chmod(dest, 0o666); await fchmod(handle, 0o666); handle.chmod(0o666); - try { - await fchmod(handle, (0o777 + 1)); - } catch (err) { - // mode can't be > 0o777 - common.expectsError({ + + // `mode` can't be > 0o777 + assert.rejects( + () => chmod(handle, (0o777 + 1)), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]' + } + ); + assert.rejects( + () => fchmod(handle, (0o777 + 1)), + { code: 'ERR_OUT_OF_RANGE', - type: RangeError - })(err); - } + name: 'RangeError [ERR_OUT_OF_RANGE]' + } + ); + assert.rejects( + () => handle.chmod(handle, (0o777 + 1)), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError [ERR_INVALID_ARG_TYPE]' + } + ); await utimes(dest, new Date(), new Date()); @@ -167,16 +183,15 @@ function verifyStatObject(stat) { await rmdir(newdir); await mkdtemp(path.resolve(tmpDir, 'FOO')); - try { - await mkdtemp(1); - } catch (err) { + assert.rejects( // mkdtemp() expects to get a string prefix. - console.log('err', err); - common.expectsError({ + async () => mkdtemp(1), + { code: 'ERR_INVALID_ARG_TYPE', - type: TypeError - })(err); - } + name: 'TypeError [ERR_INVALID_ARG_TYPE]' + } + ); + } doTest().then(common.mustCall()); From d1ac66f0bf6af5b9e39cb463a12aed778b77bfa3 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Mon, 30 Apr 2018 17:09:23 -0400 Subject: [PATCH 3/3] Add missing await + async on calls to chmod(), fchmod() --- test/parallel/test-fs-promises.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 887552bde2653c..db365e4ef87896 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -106,25 +106,25 @@ function verifyStatObject(stat) { await chmod(dest, 0o666); await fchmod(handle, 0o666); - handle.chmod(0o666); + await handle.chmod(0o666); // `mode` can't be > 0o777 assert.rejects( - () => chmod(handle, (0o777 + 1)), + async () => chmod(handle, (0o777 + 1)), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError [ERR_INVALID_ARG_TYPE]' } ); assert.rejects( - () => fchmod(handle, (0o777 + 1)), + async () => fchmod(handle, (0o777 + 1)), { code: 'ERR_OUT_OF_RANGE', name: 'RangeError [ERR_OUT_OF_RANGE]' } ); assert.rejects( - () => handle.chmod(handle, (0o777 + 1)), + async () => handle.chmod(handle, (0o777 + 1)), { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError [ERR_INVALID_ARG_TYPE]'