From 1458711846c057750126bb4c85f6468ab4120103 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 18 Mar 2019 18:22:54 +0100 Subject: [PATCH] test: remove internal error tests These tests tested internal functionality in a way that bypassed all code that could reach these cases. It gives a false feeling of safety that some code works as intended while there is no guarantee that it indeed works as it should. Therefore it seemed best to remove all of these. The only thing that should be tested is the raw functionality of the internal errors. PR-URL: https://github.com/nodejs/node/pull/26752 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- test/parallel/test-internal-errors.js | 135 +------------------------- 1 file changed, 5 insertions(+), 130 deletions(-) diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index e53a9a9fe42ca8..bf1983f3b3759a 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -6,7 +6,6 @@ const { restoreStdout, } = require('../common/hijackstdio'); -const { internalBinding } = require('internal/test/binding'); const assert = require('assert'); const errors = require('internal/errors'); @@ -101,125 +100,11 @@ common.expectsError(() => { message: /\+ message: 'Error for testing purposes: a',\n- message: \/\^Error/ }); -// Test ERR_INVALID_FD_TYPE -assert.strictEqual(errors.getMessage('ERR_INVALID_FD_TYPE', ['a']), - 'Unsupported fd type: a'); - -// Test ERR_INVALID_URL_SCHEME -assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', ['file']), - 'The URL must be of scheme file'); -assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', [['file']]), - 'The URL must be of scheme file'); -assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', - [['http', 'ftp']]), - 'The URL must be one of scheme http or ftp'); -assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', - [['a', 'b', 'c']]), - 'The URL must be one of scheme a, b, or c'); -common.expectsError( - () => errors.getMessage('ERR_INVALID_URL_SCHEME', [[]]), - { - code: 'ERR_ASSERTION', - type: assert.AssertionError, - message: /^At least one expected value needs to be specified$/ - }); - -// Test ERR_MISSING_ARGS -assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name']), - 'The "name" argument must be specified'); -assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name', 'value']), - 'The "name" and "value" arguments must be specified'); -assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['a', 'b', 'c']), - 'The "a", "b", and "c" arguments must be specified'); - -// Test ERR_SOCKET_BAD_PORT -assert.strictEqual( - errors.getMessage('ERR_SOCKET_BAD_PORT', [0]), - 'Port should be >= 0 and < 65536. Received 0.'); - -// Test ERR_TLS_CERT_ALTNAME_INVALID -assert.strictEqual( - errors.getMessage('ERR_TLS_CERT_ALTNAME_INVALID', ['altname']), - 'Hostname/IP does not match certificate\'s altnames: altname'); - -assert.strictEqual( - errors.getMessage('ERR_INVALID_PROTOCOL', ['bad protocol', 'http']), - 'Protocol "bad protocol" not supported. Expected "http"' -); - -assert.strictEqual( - errors.getMessage('ERR_HTTP_HEADERS_SENT', ['render']), - 'Cannot render headers after they are sent to the client' -); - -assert.strictEqual( - errors.getMessage('ERR_INVALID_HTTP_TOKEN', ['Method', 'foo']), - 'Method must be a valid HTTP token ["foo"]' -); - -assert.strictEqual( - errors.getMessage('ERR_OUT_OF_RANGE', ['A', 'some values', 'B']), - 'The value of "A" is out of range. It must be some values. Received B' -); - -assert.strictEqual( - errors.getMessage('ERR_UNESCAPED_CHARACTERS', ['Request path']), - 'Request path contains unescaped characters' -); - -// Test ERR_DNS_SET_SERVERS_FAILED -assert.strictEqual( - errors.getMessage('ERR_DNS_SET_SERVERS_FAILED', ['err', 'servers']), - 'c-ares failed to set servers: "err" [servers]'); - -// Test ERR_ENCODING_NOT_SUPPORTED -assert.strictEqual( - errors.getMessage('ERR_ENCODING_NOT_SUPPORTED', ['enc']), - 'The "enc" encoding is not supported'); - -// Test error messages for async_hooks -assert.strictEqual( - errors.getMessage('ERR_ASYNC_CALLBACK', ['init']), - 'init must be a function'); -assert.strictEqual( - errors.getMessage('ERR_ASYNC_TYPE', [{}]), - 'Invalid name for async "type": [object Object]'); -assert.strictEqual( - errors.getMessage('ERR_INVALID_ASYNC_ID', ['asyncId', undefined]), - 'Invalid asyncId value: undefined'); - -{ - const { kMaxLength } = internalBinding('buffer'); - const error = new errors.codes.ERR_BUFFER_TOO_LARGE(); - assert.strictEqual( - error.message, - `Cannot create a Buffer larger than 0x${kMaxLength.toString(16)} bytes` - ); -} - -{ - const error = new errors.codes.ERR_INVALID_ARG_VALUE('foo', '\u0000bar'); - assert.strictEqual( - error.message, - 'The argument \'foo\' is invalid. Received \'\\u0000bar\'' - ); -} - -{ - const error = new errors.codes.ERR_INVALID_ARG_VALUE( - 'foo', { a: 1 }, 'must have property \'b\'' - ); - assert.strictEqual( - error.message, - 'The argument \'foo\' must have property \'b\'. Received { a: 1 }' - ); -} - // Test that `code` property is mutable and that changing it does not change the // name. { - const myError = new errors.codes.ERR_TLS_HANDSHAKE_TIMEOUT(); - assert.strictEqual(myError.code, 'ERR_TLS_HANDSHAKE_TIMEOUT'); + const myError = new errors.codes.TEST_ERROR_1('foo'); + assert.strictEqual(myError.code, 'TEST_ERROR_1'); assert.strictEqual(myError.hasOwnProperty('code'), false); assert.strictEqual(myError.hasOwnProperty('name'), false); assert.deepStrictEqual(Object.keys(myError), []); @@ -228,7 +113,7 @@ assert.strictEqual( assert.strictEqual(myError.code, 'FHQWHGADS'); assert.strictEqual(myError.name, initialName); assert.deepStrictEqual(Object.keys(myError), ['code']); - assert.ok(myError.name.includes('ERR_TLS_HANDSHAKE_TIMEOUT')); + assert.ok(myError.name.includes('TEST_ERROR_1')); assert.ok(!myError.name.includes('FHQWHGADS')); } @@ -236,7 +121,7 @@ assert.strictEqual( // `console.log()` results, which is the behavior of `Error` objects in the // browser. Note that `name` becomes enumerable after being assigned. { - const myError = new errors.codes.ERR_TLS_HANDSHAKE_TIMEOUT(); + const myError = new errors.codes.TEST_ERROR_1('foo'); assert.deepStrictEqual(Object.keys(myError), []); const initialToString = myError.toString(); @@ -251,7 +136,7 @@ assert.strictEqual( { let initialConsoleLog = ''; hijackStdout((data) => { initialConsoleLog += data; }); - const myError = new errors.codes.ERR_TLS_HANDSHAKE_TIMEOUT(); + const myError = new errors.codes.TEST_ERROR_1('foo'); assert.deepStrictEqual(Object.keys(myError), []); const initialToString = myError.toString(); console.log(myError); @@ -269,13 +154,3 @@ assert.strictEqual( restoreStdout(); } - -{ - const error = new errors.codes.ERR_WORKER_INVALID_EXEC_ARGV( - ['--foo, --bar'] - ); - assert.strictEqual( - error.message, - 'Initiated Worker with invalid execArgv flags: --foo, --bar' - ); -}