Browse Source

test: favor strict equality in http tests

PR-URL: https://github.com/nodejs/node/pull/8151
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v4.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
eec078cd66
  1. 2
      test/parallel/test-http-agent.js
  2. 2
      test/parallel/test-http-allow-req-after-204-res.js
  3. 2
      test/parallel/test-http-client-abort.js
  4. 4
      test/parallel/test-http-client-timeout-agent.js
  5. 2
      test/parallel/test-http-exceptions.js
  6. 2
      test/parallel/test-http-expect-continue.js
  7. 4
      test/parallel/test-http-get-pipeline-problem.js
  8. 2
      test/parallel/test-http-incoming-pipelined-socket-destroy.js
  9. 4
      test/parallel/test-http-legacy.js
  10. 2
      test/parallel/test-http-malformed-request.js
  11. 12
      test/parallel/test-http-server.js
  12. 6
      test/parallel/test-http-set-cookies.js
  13. 6
      test/parallel/test-http-set-trailers.js
  14. 2
      test/parallel/test-http-timeout.js
  15. 6
      test/parallel/test-http-upgrade-server.js
  16. 2
      test/pummel/test-http-upload-timeout.js

2
test/parallel/test-http-agent.js

@ -19,7 +19,7 @@ server.listen(0, function() {
for (var j = 0; j < M; j++) {
http.get({ port: port, path: '/' }, function(res) {
console.log('%d %d', responses, res.statusCode);
if (++responses == N * M) {
if (++responses === N * M) {
console.error('Received all responses, closing server');
server.close();
}

2
test/parallel/test-http-allow-req-after-204-res.js

@ -28,7 +28,7 @@ function nextRequest() {
path: '/'
}, function(response) {
response.on('end', function() {
if (methods.length == 0) {
if (methods.length === 0) {
console.error('close server');
server.close();
} else {

2
test/parallel/test-http-client-abort.js

@ -43,7 +43,7 @@ server.listen(0, function() {
console.log('Client response code ' + res.statusCode);
res.resume();
if (++responses == N) {
if (++responses === N) {
console.log('All clients connected, destroying.');
requests.forEach(function(outReq) {
console.log('abort');

4
test/parallel/test-http-client-timeout-agent.js

@ -71,6 +71,6 @@ server.listen(0, options.host, function() {
process.on('exit', function() {
console.error('done=%j sent=%j', requests_done, requests_sent);
assert.ok(requests_done == requests_sent,
'timeout on http request called too much');
assert.strictEqual(requests_done, requests_sent,
'timeout on http request called too much');
});

2
test/parallel/test-http-exceptions.js

@ -20,6 +20,6 @@ var exception_count = 0;
process.on('uncaughtException', function(err) {
console.log('Caught an exception: ' + err);
if (err.name === 'AssertionError') throw err;
if (++exception_count == 4) process.exit(0);
if (++exception_count === 4) process.exit(0);
});

2
test/parallel/test-http-expect-continue.js

@ -58,7 +58,7 @@ server.on('listening', function() {
assert.equal(body, test_res_body, 'Response body doesn\'t match.');
assert.ok('abcd' in res.headers, 'Response headers missing.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}

4
test/parallel/test-http-get-pipeline-problem.js

@ -19,7 +19,7 @@ var total = 10;
var requests = 0, responses = 0;
var server = http.Server(function(req, res) {
if (++requests == total) {
if (++requests === total) {
server.close();
}
@ -51,7 +51,7 @@ server.listen(0, function() {
s.on('finish', function() {
console.error('done ' + x);
if (++responses == total) {
if (++responses === total) {
checkFiles();
}
});

2
test/parallel/test-http-incoming-pipelined-socket-destroy.js

@ -52,7 +52,7 @@ server.listen(0, function() {
var client = net.connect({ port: this.address().port });
var done = 0;
server.on('requestDone', function() {
if (++done == seeds.length) {
if (++done === seeds.length) {
server.close();
}
});

4
test/parallel/test-http-legacy.js

@ -10,7 +10,7 @@ var body0 = '';
var body1 = '';
var server = http.createServer(function(req, res) {
if (responses_sent == 0) {
if (responses_sent === 0) {
assert.equal('GET', req.method);
assert.equal('/hello', url.parse(req.url).pathname);
@ -22,7 +22,7 @@ var server = http.createServer(function(req, res) {
assert.equal('bar', req.headers['foo']);
}
if (responses_sent == 1) {
if (responses_sent === 1) {
assert.equal('POST', req.method);
assert.equal('/world', url.parse(req.url).pathname);
this.close();

2
test/parallel/test-http-malformed-request.js

@ -18,7 +18,7 @@ var server = http.createServer(function(req, res) {
res.write('Hello World');
res.end();
if (++nrequests_completed == nrequests_expected) server.close();
if (++nrequests_completed === nrequests_expected) server.close();
});
server.listen(0);

12
test/parallel/test-http-server.js

@ -15,23 +15,23 @@ var server = http.createServer(function(req, res) {
res.id = request_number;
req.id = request_number++;
if (req.id == 0) {
if (req.id === 0) {
assert.equal('GET', req.method);
assert.equal('/hello', url.parse(req.url).pathname);
assert.equal('world', qs.parse(url.parse(req.url).query).hello);
assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo);
}
if (req.id == 1) {
if (req.id === 1) {
assert.equal('POST', req.method);
assert.equal('/quit', url.parse(req.url).pathname);
}
if (req.id == 2) {
if (req.id === 2) {
assert.equal('foo', req.headers['x-x']);
}
if (req.id == 3) {
if (req.id === 3) {
assert.equal('bar', req.headers['x-x']);
this.close();
}
@ -60,12 +60,12 @@ server.on('listening', function() {
c.on('data', function(chunk) {
server_response += chunk;
if (requests_sent == 1) {
if (requests_sent === 1) {
c.write('POST /quit HTTP/1.1\r\n\r\n');
requests_sent += 1;
}
if (requests_sent == 2) {
if (requests_sent === 2) {
c.write('GET / HTTP/1.1\r\nX-X: foo\r\n\r\n' +
'GET / HTTP/1.1\r\nX-X: bar\r\n\r\n');
// Note: we are making the connection half-closed here

6
test/parallel/test-http-set-cookies.js

@ -6,7 +6,7 @@ var http = require('http');
var nresponses = 0;
var server = http.createServer(function(req, res) {
if (req.url == '/one') {
if (req.url === '/one') {
res.writeHead(200, [['set-cookie', 'A'],
['content-type', 'text/plain']]);
res.end('one\n');
@ -34,7 +34,7 @@ server.on('listening', function() {
});
res.on('end', function() {
if (++nresponses == 2) {
if (++nresponses === 2) {
server.close();
}
});
@ -51,7 +51,7 @@ server.on('listening', function() {
});
res.on('end', function() {
if (++nresponses == 2) {
if (++nresponses === 2) {
server.close();
}
});

6
test/parallel/test-http-set-trailers.js

@ -35,7 +35,7 @@ server.on('listening', function() {
c.end();
assert.ok(!/x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}
@ -66,7 +66,7 @@ server.on('listening', function() {
/0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer),
'No trailer in HTTP/1.1 response.'
);
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}
@ -85,7 +85,7 @@ server.on('listening', function() {
//console.log(res.trailers);
assert.ok('x-foo' in res.trailers, 'Client doesn\'t see trailers.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}

2
test/parallel/test-http-timeout.js

@ -29,7 +29,7 @@ server.listen(0, function() {
res.on('end', function() {
count++;
if (count == 11) {
if (count === 11) {
server.close();
}
});

6
test/parallel/test-http-upgrade-server.js

@ -38,7 +38,7 @@ function testServer() {
socket.on('data', function(d) {
var data = d.toString('utf8');
if (data == 'kill') {
if (data === 'kill') {
socket.end();
} else {
socket.write(data, 'utf8');
@ -78,11 +78,11 @@ function test_upgrade_with_listener() {
assert.equal('string', typeof data);
if (state == 1) {
if (state === 1) {
assert.equal('HTTP/1.1 101', data.substr(0, 12));
assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8'));
conn.write('test', 'utf8');
} else if (state == 2) {
} else if (state === 2) {
assert.equal('test', data);
conn.write('kill', 'utf8');
}

2
test/pummel/test-http-upload-timeout.js

@ -16,7 +16,7 @@ server.on('request', function(req, res) {
connections--;
res.writeHead(200);
res.end('done\n');
if (connections == 0) {
if (connections === 0) {
server.close();
}
});

Loading…
Cancel
Save