-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Increase test coverage for fs/promises.js #19811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, thank you for spotting this. I'll fix. |
||
| try { | ||
| await fchmod(handle, (0o777 + 1)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better, if did this for |
||
| } catch (err) { | ||
| // mode can't be > 0o777 | ||
| common.expectsError({ | ||
| code: 'ERR_OUT_OF_RANGE', | ||
| type: RangeError | ||
| })(err); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a general note: we can actually use the following instead: assert.rejects(
// `mode` can't be > 0o777
() => fchmod(handle, (0o777 + 1)),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]'
}
); |
||
|
|
||
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can you please remove the console.log here? |
||
| common.expectsError({ | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError | ||
| })(err); | ||
| } | ||
| } | ||
|
|
||
| doTest().then(common.mustCall()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be compared with
buf2?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Also, if we reduce magic numbers (like 11 in this case) it would be better.