From 5519d8ecf70de14b05ab7918a6d2c0efb7175f01 Mon Sep 17 00:00:00 2001 From: Michael Lefkowitz Date: Fri, 6 Jan 2017 22:11:42 -0600 Subject: [PATCH 1/2] 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 --- ...st-zlib-from-gzip-with-trailing-garbage.js | 22 ++++++++++++++----- 1 file changed, 16 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 37f89f5b94bf08..3644f313a5d514 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,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); })); @@ -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); })); From d0cbf503c005a34a120f9f9c192ee07e56846b6e Mon Sep 17 00:00:00 2001 From: Michael Lefkowitz Date: Sat, 7 Jan 2017 10:12:20 -0600 Subject: [PATCH 2/2] test: added addtl tests to zlib-from-gzip-with-trailing-garbage * restore result args and validate response * validate error message and code --- .../test-zlib-from-gzip-with-trailing-garbage.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 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 3644f313a5d514..872c2581c53b90 100644 --- a/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js +++ b/test/parallel/test-zlib-from-gzip-with-trailing-garbage.js @@ -37,8 +37,11 @@ assert.throws( /^Error: unknown compression method$/ ); -zlib.gunzip(data, common.mustCall((err) => { - assert(err); +zlib.gunzip(data, common.mustCall((err, result) => { + 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 @@ -54,6 +57,9 @@ assert.throws( /^Error: unknown compression method$/ ); -zlib.gunzip(data, common.mustCall((err) => { - assert(err); +zlib.gunzip(data, common.mustCall((err, result) => { + assert(err instanceof Error); + assert.strictEqual(err.code, 'Z_DATA_ERROR'); + assert.strictEqual(err.message, 'unknown compression method'); + assert.strictEqual(result, undefined); }));