-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
test: add test coverage for fs.truncate #23620
test: add test coverage for fs.truncate #23620
Conversation
Hello @christian-bromann and thank you for the contribution 🥇 |
the following: Lines 617 to 622 in bcbb937
Is a sort of JS idiom to handle optional function arguments. IMHO it could stay as as. |
test/parallel/test-fs-truncate.js
Outdated
{ | ||
const file8 = path.resolve(tmp, 'truncate-file-8.txt'); | ||
fs.truncate(file8, 0, common.mustCall(function(err) { | ||
assert.ok(err); |
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.
If we are expecting an error, its bettor to explicitly assert the error. But, I think you meant to write assert.ifError
here.
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.
Since this passes CI, I'm assuming it fails with code ENOENT
.
Assertion should have been near
node/test/parallel/test-fs-error-messages.js
Lines 521 to 545 in 9f7e3a4
// ftruncate | |
{ | |
const validateError = (err) => { | |
assert.strictEqual(err.syscall, 'ftruncate'); | |
// Could be EBADF or EINVAL, depending on the platform | |
if (err.code === 'EBADF') { | |
assert.strictEqual(err.message, 'EBADF: bad file descriptor, ftruncate'); | |
assert.strictEqual(err.errno, UV_EBADF); | |
} else { | |
assert.strictEqual(err.message, 'EINVAL: invalid argument, ftruncate'); | |
assert.strictEqual(err.errno, UV_EINVAL); | |
assert.strictEqual(err.code, 'EINVAL'); | |
} | |
return true; | |
}; | |
common.runWithInvalidFD((fd) => { | |
fs.ftruncate(fd, 4, common.mustCall(validateError)); | |
assert.throws( | |
() => fs.ftruncateSync(fd, 4), | |
validateError | |
); | |
}); | |
} |
But since it's not, I agree it should be here.
13a578a
to
7299332
Compare
@thefourtheye added explicit check for error |
test/parallel/test-fs-truncate.js
Outdated
} | ||
|
||
{ | ||
const file8 = path.resolve(tmp, 'truncate-file-8.txt'); |
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: maybe use some more descriptive filename that will indicate that this file is indeed non-existent and make sure that nobody creates it accidentally (via other test), perhaps: 'non-existent-truncate-file.txt'
?
test/parallel/test-fs-truncate.js
Outdated
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError [ERR_INVALID_ARG_TYPE]', | ||
message: 'The "len" argument must be of type number. ' + | ||
`Received type ${typeof input}` |
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: this line should be aligned to the '
7299332
to
2a1b66d
Compare
It says |
/cc @Trott @christian-bromann It’s not the first time that that happened, but I think we thought we had fixed it. I don’t think you need to do anything here, though. |
Maybe to add context to this situation: I used |
2a1b66d
to
106a6ed
Compare
Add test to check: - for `null` as len parameter - if error is propagated into callback if file doesn't exist - if an error is actually thrown if len is not a number PR-URL: nodejs#23620 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
106a6ed
to
74f854e
Compare
Landed in 74f854e 🎉 |
Will try my best. Thanks for the support. I really enjoyed the code and learn session at Node+JS Interactive. |
Add test to check: - for `null` as len parameter - if error is propagated into callback if file doesn't exist - if an error is actually thrown if len is not a number PR-URL: #23620 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Add test to check: - for `null` as len parameter - if error is propagated into callback if file doesn't exist - if an error is actually thrown if len is not a number PR-URL: #23620 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Add test to check: - for `null` as len parameter - if error is propagated into callback if file doesn't exist - if an error is actually thrown if len is not a number PR-URL: #23620 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Add test to check: - for `null` as len parameter - if error is propagated into callback if file doesn't exist - if an error is actually thrown if len is not a number PR-URL: #23620 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Add test to check: - for `null` as len parameter - if error is propagated into callback if file doesn't exist - if an error is actually thrown if len is not a number PR-URL: #23620 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Add test to check:
null
as len parameterI think it is safe to say that we could remove:
because there is an
validateInteger(len, 'len');
right after. Another option would be to just setlen
to0
for all cases it is not aNumber
. What do you think?Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes