Repository navigation
test: refactor of zlib-from-gzip-with-trailing-garbage #10674
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
* use assert.strictEqual instead of assert.equal * add RegExp in second argument of assert.throws * removed unused arguments
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,15 @@ let data = Buffer.concat([ | |
| Buffer(10).fill(0) | ||
| ]); | ||
|
|
||
| assert.equal(zlib.gunzipSync(data).toString(), 'abcdef'); | ||
| assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef'); | ||
|
|
||
| zlib.gunzip(data, common.mustCall((err, result) => { | ||
| assert.ifError(err); | ||
| assert.equal(result, 'abcdef', 'result should match original string'); | ||
| assert.strictEqual( | ||
| result.toString(), | ||
| 'abcdef', | ||
| 'result should match original string' | ||
| ); | ||
| })); | ||
|
|
||
| // if the trailing garbage happens to look like a gzip header, it should | ||
|
|
@@ -28,9 +32,12 @@ data = Buffer.concat([ | |
| Buffer(10).fill(0) | ||
| ]); | ||
|
|
||
| assert.throws(() => zlib.gunzipSync(data)); | ||
| assert.throws( | ||
| () => zlib.gunzipSync(data), | ||
| /^Error: unknown compression method$/ | ||
| ); | ||
|
|
||
| zlib.gunzip(data, common.mustCall((err, result) => { | ||
| zlib.gunzip(data, common.mustCall((err) => { | ||
| assert(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. it would likely be worthwhile validating the details of the error reported
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. I would also recommend restoring assert(err instanceof Error);
assert.strictEqual(err.code, 'Z_DATA_ERROR');
assert.strictEqual(err.message, 'unknown compression method');
assert.strictEqual(result, undefined);
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. New commit pushed up with these suggestions included. Thanks to the both of you for the help. Long time listener, first time committer. 😄 |
||
| })); | ||
|
|
||
|
|
@@ -42,8 +49,11 @@ data = Buffer.concat([ | |
| Buffer([0x1f, 0x8b, 0xff, 0xff]) | ||
| ]); | ||
|
|
||
| assert.throws(() => zlib.gunzipSync(data)); | ||
| assert.throws( | ||
| () => zlib.gunzipSync(data), | ||
| /^Error: unknown compression method$/ | ||
| ); | ||
|
|
||
| zlib.gunzip(data, common.mustCall((err, result) => { | ||
| zlib.gunzip(data, common.mustCall((err) => { | ||
| assert(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.
Same suggestions here as above. Restore
result, add an assertion to confirm it isundefined, and do some more rigorous checking onerr.