diff options
author | Michael Lefkowitz <lefkowitz.michael@gmail.com> | 2017-01-06 22:11:42 -0600 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-01-09 21:08:41 -0800 |
commit | 39c4af580cdd7292d8a0c6aa01acffbcfc55cc4d (patch) | |
tree | 9b6604ba11b22fcba1280bf58a0f9ed1d1bf2b29 /test/parallel/test-zlib-from-gzip-with-trailing-garbage.js | |
parent | 41567ee9d816b3adb94fc7bf67ca3a6cef7edc1f (diff) | |
download | android-node-v8-39c4af580cdd7292d8a0c6aa01acffbcfc55cc4d.tar.gz android-node-v8-39c4af580cdd7292d8a0c6aa01acffbcfc55cc4d.tar.bz2 android-node-v8-39c4af580cdd7292d8a0c6aa01acffbcfc55cc4d.zip |
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: https://github.com/nodejs/node/pull/10674
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/parallel/test-zlib-from-gzip-with-trailing-garbage.js')
-rw-r--r-- | test/parallel/test-zlib-from-gzip-with-trailing-garbage.js | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js index 37f89f5b94..872c2581c5 100644 --- a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js +++ b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js @@ -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,10 +32,16 @@ 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) => { - assert(err); + assert(err instanceof Error); + assert.strictEqual(err.code, 'Z_DATA_ERROR'); + assert.strictEqual(err.message, 'unknown compression method'); + assert.strictEqual(result, undefined); })); // In this case the trailing junk is too short to be a gzip segment @@ -42,8 +52,14 @@ 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) => { - assert(err); + assert(err instanceof Error); + assert.strictEqual(err.code, 'Z_DATA_ERROR'); + assert.strictEqual(err.message, 'unknown compression method'); + assert.strictEqual(result, undefined); })); |