test: refactoring test with common.mustCall

PR-URL: https://github.com/nodejs/node/pull/12702
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
weewey 2017-04-28 11:21:01 +08:00 committed by Anna Henningsen
parent 6058c4349f
commit 152966dbb5
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF

View File

@ -55,28 +55,31 @@ const serverCallback = common.mustCall(function(req, res) {
const server = https.createServer(options, serverCallback);
server.listen(0, function() {
server.listen(0, common.mustCall(() => {
// Do a request ignoring the unauthorized server certs
const port = server.address().port;
const noCertCheckOptions = {
hostname: '127.0.0.1',
port: this.address().port,
port: port,
path: '/',
method: 'GET',
rejectUnauthorized: false
};
noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions);
const req = https.request(noCertCheckOptions, function(res) {
const req = https.request(noCertCheckOptions, common.mustCall((res) => {
let responseBody = '';
res.on('data', function(d) {
responseBody = responseBody + d;
});
res.on('end', function() {
res.on('end', common.mustCall(() => {
assert.strictEqual(responseBody, body);
testSucceeded();
});
});
}));
}));
req.end();
req.on('error', function(e) {
@ -86,7 +89,7 @@ server.listen(0, function() {
// Do a request that throws error due to the invalid server certs
const checkCertOptions = {
hostname: '127.0.0.1',
port: this.address().port,
port: port,
path: '/',
method: 'GET'
};
@ -102,11 +105,11 @@ server.listen(0, function() {
});
checkCertReq.end();
checkCertReq.on('error', function(e) {
checkCertReq.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
testSucceeded();
});
});
}));
}));
process.on('exit', function() {
assert.strictEqual(successful, tests);