Skip to content

Commit cf5579d

Browse files
lfkwtzitaloacasas
authored andcommittedJan 27, 2017
test: improve zlib-from-gzip-with-trailing-garbage
* use assert.strictEqual instead of assert.equal * add RegExp in second argument of assert.throws * validate error message and code PR-URL: #10674 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 2d85609 commit cf5579d

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed
 

‎test/parallel/test-zlib-from-gzip-with-trailing-garbage.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ let data = Buffer.concat([
1212
Buffer(10).fill(0)
1313
]);
1414

15-
assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');
15+
assert.strictEqual(zlib.gunzipSync(data).toString(), 'abcdef');
1616

1717
zlib.gunzip(data, common.mustCall((err, result) => {
1818
assert.ifError(err);
19-
assert.equal(result, 'abcdef', 'result should match original string');
19+
assert.strictEqual(
20+
result.toString(),
21+
'abcdef',
22+
'result should match original string'
23+
);
2024
}));
2125

2226
// if the trailing garbage happens to look like a gzip header, it should
@@ -28,10 +32,16 @@ data = Buffer.concat([
2832
Buffer(10).fill(0)
2933
]);
3034

31-
assert.throws(() => zlib.gunzipSync(data));
35+
assert.throws(
36+
() => zlib.gunzipSync(data),
37+
/^Error: unknown compression method$/
38+
);
3239

3340
zlib.gunzip(data, common.mustCall((err, result) => {
34-
assert(err);
41+
assert(err instanceof Error);
42+
assert.strictEqual(err.code, 'Z_DATA_ERROR');
43+
assert.strictEqual(err.message, 'unknown compression method');
44+
assert.strictEqual(result, undefined);
3545
}));
3646

3747
// In this case the trailing junk is too short to be a gzip segment
@@ -42,8 +52,14 @@ data = Buffer.concat([
4252
Buffer([0x1f, 0x8b, 0xff, 0xff])
4353
]);
4454

45-
assert.throws(() => zlib.gunzipSync(data));
55+
assert.throws(
56+
() => zlib.gunzipSync(data),
57+
/^Error: unknown compression method$/
58+
);
4659

4760
zlib.gunzip(data, common.mustCall((err, result) => {
48-
assert(err);
61+
assert(err instanceof Error);
62+
assert.strictEqual(err.code, 'Z_DATA_ERROR');
63+
assert.strictEqual(err.message, 'unknown compression method');
64+
assert.strictEqual(result, undefined);
4965
}));

0 commit comments

Comments
 (0)
Please sign in to comment.