Skip to content

Commit a8e40a9

Browse files
ZYSzystargos
authored andcommitted
test: add test for options validation of createServer
PR-URL: #30541 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 51a92b9 commit a8e40a9

3 files changed

+70
-22
lines changed

test/parallel/test-http2-createsecureserver-nooptions.js

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
10+
// Error if invalid options are passed to createSecureServer
11+
const invalidOptions = [() => {}, 1, 'test', null, Symbol('test')];
12+
invalidOptions.forEach((invalidOption) => {
13+
assert.throws(
14+
() => http2.createSecureServer(invalidOption),
15+
{
16+
name: 'TypeError',
17+
code: 'ERR_INVALID_ARG_TYPE',
18+
message: 'The "options" argument must be of type Object. Received ' +
19+
`type ${typeof invalidOption}`
20+
}
21+
);
22+
});
23+
24+
// Error if invalid options.settings are passed to createSecureServer
25+
invalidOptions.forEach((invalidSettingsOption) => {
26+
assert.throws(
27+
() => http2.createSecureServer({ settings: invalidSettingsOption }),
28+
{
29+
name: 'TypeError',
30+
code: 'ERR_INVALID_ARG_TYPE',
31+
message: 'The "options.settings" property must be of type Object. ' +
32+
`Received type ${typeof invalidSettingsOption}`
33+
}
34+
);
35+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
10+
// Error if invalid options are passed to createServer
11+
const invalidOptions = [1, true, 'test', null, Symbol('test')];
12+
invalidOptions.forEach((invalidOption) => {
13+
assert.throws(
14+
() => http2.createServer(invalidOption),
15+
{
16+
name: 'TypeError',
17+
code: 'ERR_INVALID_ARG_TYPE',
18+
message: 'The "options" argument must be of type Object. Received ' +
19+
`type ${typeof invalidOption}`
20+
}
21+
);
22+
});
23+
24+
// Error if invalid options.settings are passed to createServer
25+
invalidOptions.forEach((invalidSettingsOption) => {
26+
assert.throws(
27+
() => http2.createServer({ settings: invalidSettingsOption }),
28+
{
29+
name: 'TypeError',
30+
code: 'ERR_INVALID_ARG_TYPE',
31+
message: 'The "options.settings" property must be of type Object. ' +
32+
`Received type ${typeof invalidSettingsOption}`
33+
}
34+
);
35+
});

0 commit comments

Comments
 (0)