From 35d665958eb9cdcf30c6f960e2d26151cc3926b3 Mon Sep 17 00:00:00 2001 From: abouthiroppy Date: Mon, 16 Jan 2017 01:39:25 +0900 Subject: [PATCH] test: increase coverage of _http_outgoing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit validateHeader: https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js#L376 write: https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js#L477 addTrailers: https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js#L557 PR-URL: https://github.com/nodejs/node/pull/10820 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Michaël Zasso --- test/parallel/test-http-outgoing-proto.js | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/parallel/test-http-outgoing-proto.js b/test/parallel/test-http-outgoing-proto.js index 738e1d2c8cfe4e..53198708b42b68 100644 --- a/test/parallel/test-http-outgoing-proto.js +++ b/test/parallel/test-http-outgoing-proto.js @@ -12,3 +12,63 @@ assert.strictEqual( typeof ClientRequest.prototype._implicitHeader, 'function'); assert.strictEqual( typeof ServerResponse.prototype._implicitHeader, 'function'); + +// validateHeader +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.setHeader(); +}, /^TypeError: Header name must be a valid HTTP Token \["undefined"\]$/); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.setHeader('test'); +}, /^Error: "value" required in setHeader\("test", value\)$/); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.setHeader(404); +}, /^TypeError: Header name must be a valid HTTP Token \["404"\]$/); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.setHeader.call({_header: 'test'}, 'test', 'value'); +}, /^Error: Can't set headers after they are sent.$/); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.setHeader('200', 'あ'); +}, /^TypeError: The header content contains invalid characters$/); + +// write +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.write(); +}, /^Error: _implicitHeader\(\) method is not implemented$/); + +assert(OutgoingMessage.prototype.write.call({_header: 'test'})); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.write.call({_header: 'test', _hasBody: 'test'}); +}, /^TypeError: First argument must be a string or Buffer$/); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.write.call({_header: 'test', _hasBody: 'test'}, 1); +}, /^TypeError: First argument must be a string or Buffer$/); + +// addTrailers +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.addTrailers(); +}, /^TypeError: Cannot convert undefined or null to object$/); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.addTrailers({'あ': 'value'}); +}, /^TypeError: Trailer name must be a valid HTTP Token \["あ"\]$/); + +assert.throws(() => { + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.addTrailers({404: 'あ'}); +}, /^TypeError: The trailer content contains invalid characters$/);