11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst expectedSuccesses = [undefined, null, 'GET', 'post'];
81cb0ef41Sopenharmony_ciconst expectedFails = [-1, 1, 0, {}, true, false, [], Symbol()];
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst countdown =
111cb0ef41Sopenharmony_ci  new Countdown(expectedSuccesses.length,
121cb0ef41Sopenharmony_ci                common.mustCall(() => server.close()));
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall((req, res) => {
151cb0ef41Sopenharmony_ci  res.end();
161cb0ef41Sopenharmony_ci  countdown.dec();
171cb0ef41Sopenharmony_ci}, expectedSuccesses.length));
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
201cb0ef41Sopenharmony_ci  expectedFails.forEach((method) => {
211cb0ef41Sopenharmony_ci    assert.throws(() => {
221cb0ef41Sopenharmony_ci      http.request({ method, path: '/' }, common.mustNotCall());
231cb0ef41Sopenharmony_ci    }, {
241cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
251cb0ef41Sopenharmony_ci      name: 'TypeError',
261cb0ef41Sopenharmony_ci      message: 'The "options.method" property must be of type string.' +
271cb0ef41Sopenharmony_ci               common.invalidArgTypeHelper(method)
281cb0ef41Sopenharmony_ci    });
291cb0ef41Sopenharmony_ci  });
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  expectedSuccesses.forEach((method) => {
321cb0ef41Sopenharmony_ci    http.request({ method, port: server.address().port }).end();
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci}));
35