Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: refactor of zlib-from-gzip-with-trailing-garbage
* use assert.strictEqual instead of assert.equal
* add RegExp in second argument of assert.throws
* removed unused arguments
  • Loading branch information
lfkwtz committed Jan 7, 2017
commit 5519d8ecf70de14b05ab7918a6d2c0efb7175f01
22 changes: 16 additions & 6 deletions test/parallel/test-zlib-from-gzip-with-trailing-garbage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => {

Copy link
Copy Markdown
Member

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 is undefined, and do some more rigorous checking on err.

assert(err);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would likely be worthwhile validating the details of the error reported

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also recommend restoring result as an argument and adding an assertion for it. So all together, maybe something like this?:

assert(err instanceof Error);
assert.strictEqual(err.code, 'Z_DATA_ERROR');
assert.strictEqual(err.message, 'unknown compression method');
assert.strictEqual(result, undefined);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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. 😄

}));

Expand All @@ -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);
}));