Skip to content

Commit

Permalink
test: refactoring test with common.mustCall
Browse files Browse the repository at this point in the history
PR-URL: #12702
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
weewey authored and MylesBorins committed Jul 11, 2017
1 parent 608c309 commit 8414659
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions test/parallel/test-https-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,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) {
Expand All @@ -65,7 +68,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'
};
Expand All @@ -81,11 +84,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);
Expand Down

0 comments on commit 8414659

Please sign in to comment.