summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-client-setNextStreamID-errors.js
blob: 203b552ef7f7f148bb202e0babdb5bc2df14a5b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');

const http2 = require('http2');

const server = http2.createServer();
server.on('stream', (stream) => {
  stream.respond();
  stream.end('ok');
});

const types = {
  boolean: true,
  function: () => {},
  number: 1,
  object: {},
  array: [],
  null: null,
  symbol: Symbol('test')
};

server.listen(0, common.mustCall(() => {
  const client = http2.connect(`http://localhost:${server.address().port}`);

  client.on('connect', () => {
    const outOfRangeNum = 2 ** 32;
    common.expectsError(
      () => client.setNextStreamID(outOfRangeNum),
      {
        type: RangeError,
        code: 'ERR_OUT_OF_RANGE',
        message: 'The value of "id" is out of range.' +
           ' It must be > 0 and <= 4294967295. Received ' + outOfRangeNum
      }
    );

    // Should throw if something other than number is passed to setNextStreamID
    Object.entries(types).forEach(([type, value]) => {
      if (type === 'number') {
        return;
      }

      common.expectsError(
        () => client.setNextStreamID(value),
        {
          type: TypeError,
          code: 'ERR_INVALID_ARG_TYPE',
          message: 'The "id" argument must be of type number. Received type ' +
                   typeof value
        }
      );
    });

    server.close();
    client.close();
  });
}));