test: http2 ERR_INVALID_ARG_TYPE tests
PR-URL: https://github.com/nodejs/node/pull/15766 Ref: https://github.com/nodejs/node/issues/14985 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
006fdb2fe5
commit
0ce6be07da
@ -6,39 +6,17 @@ if (!common.hasCrypto)
|
|||||||
|
|
||||||
const http2 = require('http2');
|
const http2 = require('http2');
|
||||||
|
|
||||||
|
const invalidOptions = [() => {}, 1, 'test', null, undefined];
|
||||||
|
const invalidArgTypeError = {
|
||||||
|
type: TypeError,
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
message: 'The "options" argument must be of type object'
|
||||||
|
};
|
||||||
|
|
||||||
// Error if options are not passed to createSecureServer
|
// Error if options are not passed to createSecureServer
|
||||||
|
invalidOptions.forEach((invalidOption) =>
|
||||||
common.expectsError(
|
common.expectsError(
|
||||||
() => http2.createSecureServer(),
|
() => http2.createSecureServer(invalidOption),
|
||||||
{
|
invalidArgTypeError
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
)
|
||||||
type: TypeError
|
);
|
||||||
});
|
|
||||||
|
|
||||||
common.expectsError(
|
|
||||||
() => http2.createSecureServer(() => {}),
|
|
||||||
{
|
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
|
||||||
type: TypeError
|
|
||||||
});
|
|
||||||
|
|
||||||
common.expectsError(
|
|
||||||
() => http2.createSecureServer(1),
|
|
||||||
{
|
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
|
||||||
type: TypeError
|
|
||||||
});
|
|
||||||
|
|
||||||
common.expectsError(
|
|
||||||
() => http2.createSecureServer('test'),
|
|
||||||
{
|
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
|
||||||
type: TypeError
|
|
||||||
});
|
|
||||||
|
|
||||||
common.expectsError(
|
|
||||||
() => http2.createSecureServer(null),
|
|
||||||
{
|
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
|
||||||
type: TypeError
|
|
||||||
});
|
|
||||||
|
43
test/parallel/test-http2-invalidargtypes-errors.js
Normal file
43
test/parallel/test-http2-invalidargtypes-errors.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
if (!common.hasCrypto)
|
||||||
|
common.skip('missing crypto');
|
||||||
|
const http2 = require('http2');
|
||||||
|
|
||||||
|
const server = http2.createServer();
|
||||||
|
|
||||||
|
server.on(
|
||||||
|
'stream',
|
||||||
|
common.mustCall((stream) => {
|
||||||
|
const invalidArgTypeError = (param, type) => ({
|
||||||
|
type: TypeError,
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
message: `The "${param}" argument must be of type ${type}`
|
||||||
|
});
|
||||||
|
common.expectsError(
|
||||||
|
() => stream.session.priority(undefined, {}),
|
||||||
|
invalidArgTypeError('stream', 'Http2Stream')
|
||||||
|
);
|
||||||
|
common.expectsError(
|
||||||
|
() => stream.session.rstStream(undefined),
|
||||||
|
invalidArgTypeError('stream', 'Http2Stream')
|
||||||
|
);
|
||||||
|
common.expectsError(
|
||||||
|
() => stream.session.rstStream(stream, 'string'),
|
||||||
|
invalidArgTypeError('code', 'number')
|
||||||
|
);
|
||||||
|
stream.session.destroy();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
server.listen(
|
||||||
|
0,
|
||||||
|
common.mustCall(() => {
|
||||||
|
const client = http2.connect(`http://localhost:${server.address().port}`);
|
||||||
|
const req = client.request();
|
||||||
|
req.resume();
|
||||||
|
req.on('end', common.mustCall(() => server.close()));
|
||||||
|
req.end();
|
||||||
|
})
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user