aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWeijia Wang <381152119@qq.com>2017-07-22 19:23:04 +0800
committerTobias Nießen <tniessen@tnie.de>2017-08-01 14:08:12 +0200
commitbdfbce924159ece4b32ee7f774a263987e719972 (patch)
tree2134a4937c1d751de771abe92d00c8cf47fc2307 /test
parent8db39971b768118ce2c0c34d88788daea14f52c9 (diff)
downloadandroid-node-v8-bdfbce924159ece4b32ee7f774a263987e719972.tar.gz
android-node-v8-bdfbce924159ece4b32ee7f774a263987e719972.tar.bz2
android-node-v8-bdfbce924159ece4b32ee7f774a263987e719972.zip
http_client, errors: migrate to internal/errors
PR-URL: https://github.com/nodejs/node/pull/14423 Refs: https://github.com/nodejs/node/issues/11273 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http-client-check-http-token.js7
-rw-r--r--test/parallel/test-http-client-reject-unexpected-agent.js8
-rw-r--r--test/parallel/test-http-client-unescaped-path.js10
-rw-r--r--test/parallel/test-http-hostname-typechecking.js30
-rw-r--r--test/parallel/test-http-invalid-path-chars.js9
-rw-r--r--test/parallel/test-http-request-invalid-method-error.js9
-rw-r--r--test/parallel/test-internal-errors.js25
7 files changed, 80 insertions, 18 deletions
diff --git a/test/parallel/test-http-client-check-http-token.js b/test/parallel/test-http-client-check-http-token.js
index 4fa3a44802..7a0c894504 100644
--- a/test/parallel/test-http-client-check-http-token.js
+++ b/test/parallel/test-http-client-check-http-token.js
@@ -20,7 +20,12 @@ server.listen(0, common.mustCall(() => {
expectedFails.forEach((method) => {
assert.throws(() => {
http.request({ method, path: '/' }, common.mustNotCall());
- }, /^TypeError: Method must be a string$/);
+ }, common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "method" argument must be of type string. ' +
+ `Received type ${typeof method}`
+ }));
});
expectedSuccesses.forEach((method) => {
diff --git a/test/parallel/test-http-client-reject-unexpected-agent.js b/test/parallel/test-http-client-reject-unexpected-agent.js
index f1798b483f..23439baa32 100644
--- a/test/parallel/test-http-client-reject-unexpected-agent.js
+++ b/test/parallel/test-http-client-reject-unexpected-agent.js
@@ -49,8 +49,12 @@ server.listen(0, baseOptions.host, common.mustCall(function() {
failingAgentOptions.forEach((agent) => {
assert.throws(
() => createRequest(agent),
- /^TypeError: Agent option must be an Agent-like object/,
- `Expected typeof agent: ${typeof agent} to be rejected`
+ common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "Agent option" argument must be one of type ' +
+ 'Agent-like object, undefined, or false'
+ })
);
});
diff --git a/test/parallel/test-http-client-unescaped-path.js b/test/parallel/test-http-client-unescaped-path.js
index 11faaec41a..f3c680919d 100644
--- a/test/parallel/test-http-client-unescaped-path.js
+++ b/test/parallel/test-http-client-unescaped-path.js
@@ -24,8 +24,14 @@ const common = require('../common');
const assert = require('assert');
const http = require('http');
-const errMessage = /contains unescaped characters/;
for (let i = 0; i <= 32; i += 1) {
const path = `bad${String.fromCharCode(i)}path`;
- assert.throws(() => http.get({ path }, common.mustNotCall()), errMessage);
+ assert.throws(
+ () => http.get({ path }, common.mustNotCall()),
+ common.expectsError({
+ code: 'ERR_UNESCAPED_CHARACTERS',
+ type: TypeError,
+ message: 'Request path contains unescaped characters'
+ })
+ );
}
diff --git a/test/parallel/test-http-hostname-typechecking.js b/test/parallel/test-http-hostname-typechecking.js
index 91d4d99b9a..dbb98b7ae1 100644
--- a/test/parallel/test-http-hostname-typechecking.js
+++ b/test/parallel/test-http-hostname-typechecking.js
@@ -1,6 +1,6 @@
'use strict';
-require('../common');
+const common = require('../common');
const assert = require('assert');
const http = require('http');
@@ -8,14 +8,28 @@ const http = require('http');
// when passed as the value of either options.hostname or options.host
const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];
-const errHostname =
- /^TypeError: "options\.hostname" must either be a string, undefined or null$/;
-const errHost =
- /^TypeError: "options\.host" must either be a string, undefined or null$/;
-
vals.forEach((v) => {
- assert.throws(() => http.request({ hostname: v }), errHostname);
- assert.throws(() => http.request({ host: v }), errHost);
+ assert.throws(
+ () => http.request({ hostname: v }),
+ common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "options.hostname" property must be one of ' +
+ 'type string, undefined, or null. ' +
+ `Received type ${typeof v}`
+ })
+ );
+
+ assert.throws(
+ () => http.request({ host: v }),
+ common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "options.host" property must be one of ' +
+ 'type string, undefined, or null. ' +
+ `Received type ${typeof v}`
+ })
+ );
});
// These values are OK and should not throw synchronously.
diff --git a/test/parallel/test-http-invalid-path-chars.js b/test/parallel/test-http-invalid-path-chars.js
index 6aedf430a1..c1d0baa62c 100644
--- a/test/parallel/test-http-invalid-path-chars.js
+++ b/test/parallel/test-http-invalid-path-chars.js
@@ -1,9 +1,14 @@
'use strict';
-require('../common');
+
+const common = require('../common');
const assert = require('assert');
const http = require('http');
-const expectedError = /^TypeError: Request path contains unescaped characters$/;
+const expectedError = common.expectsError({
+ code: 'ERR_UNESCAPED_CHARACTERS',
+ type: TypeError,
+ message: 'Request path contains unescaped characters'
+}, 1320);
const theExperimentallyDeterminedNumber = 39;
function fail(path) {
diff --git a/test/parallel/test-http-request-invalid-method-error.js b/test/parallel/test-http-request-invalid-method-error.js
index d5dffdd221..457e90fd48 100644
--- a/test/parallel/test-http-request-invalid-method-error.js
+++ b/test/parallel/test-http-request-invalid-method-error.js
@@ -4,7 +4,10 @@ const assert = require('assert');
const http = require('http');
assert.throws(
- () => { http.request({ method: '\0' }); },
- common.expectsError({ type: TypeError,
- message: 'Method must be a valid HTTP token' })
+ () => http.request({ method: '\0' }),
+ common.expectsError({
+ code: 'ERR_INVALID_HTTP_TOKEN',
+ type: TypeError,
+ message: 'Method must be a valid HTTP token'
+ })
);
diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js
index 1166b0bed2..8df0780e04 100644
--- a/test/parallel/test-internal-errors.js
+++ b/test/parallel/test-internal-errors.js
@@ -235,3 +235,28 @@ assert.throws(
assert.strictEqual(
errors.message('ERR_TLS_CERT_ALTNAME_INVALID', ['altname']),
'Hostname/IP does not match certificate\'s altnames: altname');
+
+assert.strictEqual(
+ errors.message('ERR_INVALID_PROTOCOL', ['bad protocol', 'http']),
+ 'Protocol "bad protocol" not supported. Expected "http"'
+);
+
+assert.strictEqual(
+ errors.message('ERR_HTTP_HEADERS_SENT'),
+ 'Cannot render headers after they are sent to the client'
+);
+
+assert.strictEqual(
+ errors.message('ERR_INVALID_DOMAIN_NAME'),
+ 'Unable to determine the domain name'
+);
+
+assert.strictEqual(
+ errors.message('ERR_INVALID_HTTP_TOKEN', ['Method']),
+ 'Method must be a valid HTTP token'
+);
+
+assert.strictEqual(
+ errors.message('ERR_UNESCAPED_CHARACTERS', ['Request path']),
+ 'Request path contains unescaped characters'
+);