Browse Source

test: add test case to test-http-response-statuscode.js

Change regular expression of error message.
Add test case(`res.writeHead()`).

PR-URL: https://github.com/nodejs/node/pull/10808
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v7.x
abouthiroppy 8 years ago
committed by Italo A. Casas
parent
commit
66c57a24c2
No known key found for this signature in database GPG Key ID: 23EFEFE93C4CFFFE
  1. 35
      test/parallel/test-http-response-statuscode.js

35
test/parallel/test-http-response-statuscode.js

@ -3,70 +3,79 @@ const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const http = require('http'); const http = require('http');
const MAX_REQUESTS = 12; const MAX_REQUESTS = 13;
let reqNum = 0; let reqNum = 0;
const createErrorMessage = (code) => {
return new RegExp(`^RangeError: Invalid status code: ${code}$`);
};
const server = http.Server(common.mustCall(function(req, res) { const server = http.Server(common.mustCall(function(req, res) {
switch (reqNum) { switch (reqNum) {
case 0: case 0:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead(-1); res.writeHead(-1);
}), /invalid status code/i); }), createErrorMessage(-1));
break; break;
case 1: case 1:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead(Infinity); res.writeHead(Infinity);
}), /invalid status code/i); }), createErrorMessage(0));
break; break;
case 2: case 2:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead(NaN); res.writeHead(NaN);
}), /invalid status code/i); }), createErrorMessage(0));
break; break;
case 3: case 3:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead({}); res.writeHead({});
}), /invalid status code/i); }), createErrorMessage(0));
break; break;
case 4: case 4:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead(99); res.writeHead(99);
}), /invalid status code/i); }), createErrorMessage(99));
break; break;
case 5: case 5:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead(1000); res.writeHead(1000);
}), /invalid status code/i); }), createErrorMessage(1000));
break; break;
case 6: case 6:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead('1000'); res.writeHead('1000');
}), /invalid status code/i); }), createErrorMessage(1000));
break; break;
case 7: case 7:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead(null); res.writeHead(null);
}), /invalid status code/i); }), createErrorMessage(0));
break; break;
case 8: case 8:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead(true); res.writeHead(true);
}), /invalid status code/i); }), createErrorMessage(1));
break; break;
case 9: case 9:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead([]); res.writeHead([]);
}), /invalid status code/i); }), createErrorMessage(0));
break; break;
case 10: case 10:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead('this is not valid'); res.writeHead('this is not valid');
}), /invalid status code/i); }), createErrorMessage(0));
break; break;
case 11: case 11:
assert.throws(common.mustCall(() => { assert.throws(common.mustCall(() => {
res.writeHead('404 this is not valid either'); res.writeHead('404 this is not valid either');
}), /invalid status code/i); }), createErrorMessage(0));
break;
case 12:
assert.throws(common.mustCall(() => {
res.writeHead();
}), createErrorMessage(0));
this.close(); this.close();
break; break;
default: default:

Loading…
Cancel
Save