mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
test: use mustCall() for simple flow tracking
Many of the tests use variables to track when callback functions are invoked or events are emitted. These variables are then asserted on process exit. This commit replaces this pattern in straightforward cases with common.mustCall(). This makes the tests easier to reason about, leads to a net reduction in lines of code, and uncovered a few bugs in tests. This commit also replaces some callbacks that should never be called with common.fail(). PR-URL: https://github.com/nodejs/node/pull/7753 Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
59741a9bee
commit
04b4d15b39
213 files changed
+1101
-2882
No files matched your search
@@ -24,25 +24,31 @@ var options = {
|
||||
requestCert: true
|
||||
};
|
||||
|
||||
const modulus = 'A6F44A9C25791431214F5C87AF9E040177A8BB89AC803F7E09BBC3A5519F' +
|
||||
'349CD9B9C40BE436D0AA823A94147E26C89248ADA2BE3DD4D34E8C289646' +
|
||||
'94B2047D217B4F1299371EA93A83C89AB9440724131E65F2B0161DE9560C' +
|
||||
'DE9C13455552B2F49CF0FB00D8D77532324913F6F80FF29D0A131D29DB06' +
|
||||
'AFF8BE191B7920DC2DAE1C26EA82A47847A10391EF3BF6AABB3CC40FF821' +
|
||||
'00B03A4F0FF1809278E4DDFDA7DE954ED56DC7AD9A47EEBC37D771A366FC' +
|
||||
'60A5BCB72373BEC180649B3EFA0E9092707210B41B90032BB18BC91F2046' +
|
||||
'EBDAF1191F4A4E26D71879C4C7867B62FCD508E8CE66E82D128A71E91580' +
|
||||
'9FCF44E8DE774067F1DE5D70B9C03687';
|
||||
|
||||
var CRLF = '\r\n';
|
||||
var body = 'hello world\n';
|
||||
var cert;
|
||||
var subjectaltname;
|
||||
var modulus;
|
||||
var exponent;
|
||||
|
||||
var server = https.createServer(options, function(req, res) {
|
||||
var server = https.createServer(options, common.mustCall(function(req, res) {
|
||||
console.log('got request');
|
||||
|
||||
cert = req.connection.getPeerCertificate();
|
||||
|
||||
subjectaltname = cert.subjectaltname;
|
||||
modulus = cert.modulus;
|
||||
exponent = cert.exponent;
|
||||
|
||||
assert.strictEqual(cert.subjectaltname, 'URI:http://example.com/#me');
|
||||
assert.strictEqual(cert.exponent, '0x10001');
|
||||
assert.strictEqual(cert.modulus, modulus);
|
||||
res.writeHead(200, { 'content-type': 'text/plain' });
|
||||
res.end(body);
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(0, function() {
|
||||
var args = ['s_client',
|
||||
@@ -70,16 +76,3 @@ server.listen(0, function() {
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.equal(subjectaltname, 'URI:http://example.com/#me');
|
||||
assert.equal(modulus, 'A6F44A9C25791431214F5C87AF9E040177A8BB89AC803F7E09' +
|
||||
'BBC3A5519F349CD9B9C40BE436D0AA823A94147E26C89248ADA2BE3DD4D34E8C2896' +
|
||||
'4694B2047D217B4F1299371EA93A83C89AB9440724131E65F2B0161DE9560CDE9C13' +
|
||||
'455552B2F49CF0FB00D8D77532324913F6F80FF29D0A131D29DB06AFF8BE191B7920' +
|
||||
'DC2DAE1C26EA82A47847A10391EF3BF6AABB3CC40FF82100B03A4F0FF1809278E4DD' +
|
||||
'FDA7DE954ED56DC7AD9A47EEBC37D771A366FC60A5BCB72373BEC180649B3EFA0E90' +
|
||||
'92707210B41B90032BB18BC91F2046EBDAF1191F4A4E26D71879C4C7867B62FCD508' +
|
||||
'E8CE66E82D128A71E915809FCF44E8DE774067F1DE5D70B9C03687');
|
||||
assert.equal(exponent, '0x10001');
|
||||
});
|
||||
Reference in new issue
Block a user